The change function is not firing to the console after I change the value in the dropdown. When I apply the code in the console and run it, changed!! logs without any problem. What could be the cause of this?  jQuery( document ).ready(function() {      /* Watch for changes in UITVERKOCHT for 50m and 100m pages and change the text */      if(window.location.href.indexOf("prikkabel-50-meter") &gt; -1 || window.location.href.indexOf("prikkabel-100-meter") &gt; -1){         console.log('window location true');         jQuery('#aantal-fittingen').change(function(){             console.log('changed!!');             if(jQuery('.woocommerce-variation-availability &gt; p').text() === "Uitverkocht"){                 jQuery('.woocommerce-variation-availability &gt; p').text('Beschikbaar');             }         });     } });   This is the page when I would like this code to work:
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
66978
I have got a problem with JavaScript. I want to add a drop down list control with a link as Value of it. After it will be choosen and clicked button it schould redirect me to chosen link. I tried this code from this Article:       &lt;select name="list" id="list" accesskey="target"&gt;     &lt;option value='none' selected&gt;Choose a theme&lt;/option&gt;     &lt;option value="index.html"&gt;Theme 1&lt;/option&gt;     &lt;option value="theme2.html"&gt;Theme 2&lt;/option&gt;     &lt;option value="theme3.html"&gt;Theme 3&lt;/option&gt; &lt;select&gt; &lt;input type=button value="Go" onclick="goToNewPage()" /&gt;  &lt;script type="text/javascript"&gt; function goToNewPage() {     var url = document.getElementById('list').value;     if(url != 'none') {         window.location = url;     } }     but when I tried to add by the script, or by html on site, or by designer its erase me that sort of text:  &lt;input type=button value="Go" onclick="goToNewPage()" /&gt;   It's live only:  &lt;input type=button value="Go" /&gt;
99580
I am new to Salesforce development. I made a trigger that creates a new asset record and autofills some of the fields on said record. What I want ultimately would be a button that I can put on the "Products" related list on the opportunity page that does what my trigger does. From what I understand, I can't just call my trigger on the button click, and I have to create a VF page or an Apex class that uses the trigger's logic. Does anyone know how I would go about doing this? Here's my code:  trigger ConvertOpportunitiesToAssets on Opportunity (after update) {      List&lt;Asset&gt; a = new List&lt;Asset&gt;();     OpportunityLineItem oli = new OpportunityLineItem();      for(Opportunity o: Trigger.new)     {                   a.add( new Asset(             PSI_Supplier__c = o.Supplier__c,             PSI_Opportunity__c = oli.Product2Id,             AccountId = o.Accountid,             Name = oli.Product2Id,             Product2Id = oli.Product2Id,             Product_Name__c = oli.Product_Name__c             ));            }     insert a; }   Thanks in advance!  UPDATE So I tried making the trigger into a class and button (thanks sfdcfox!), but now it won't work. Here's what I've got:      global class OpportunityWS{     webservice static void createAsset(Id opportunityId)     {         List&lt;Asset&gt; a = new List&lt;Asset&gt;();         Opportunity o = new Opportunity();         OpportunityLineItem oli = new OpportunityLineItem();          a.add( new Asset(             PSI_Supplier__c = o.Supplier__c,             PSI_Opportunity__c = oli.Product2Id,             AccountId = o.Accountid,             Name = oli.Product2Id,             Product2Id = oli.Product2Id,             Product_Name__c = oli.Product_Name__c             ));                 insert a;      } }  {!RequireScript("/soap/ajax/34.0/connection.js")} {!RequireScript("/soap/ajax/34.0/apex.js")} function success() { var alertString="Success!";  alert(alertString);  } function error() { var alertString="Error!";  alert(alertString);  } sforce.connection.sessionId = "{!$Api.Session_ID}"; sforce.apex.execute("OpportunityWS", "createAsset", { opportunityId: "{!Opportunity.Id}" }, { onSuccess: success, onFailure: error });   I can't tell if it's something wrong with the class or the button. I think it must be the class.  UPDATE(AGAIN) Alright so I followed Doug's advice and tried to use the opportunityId to query the opportunity and opportunityLineItem sobjects, was able to compile without errors. But now I'm getting the error message that I made in the button thrown and the asset isn't being created. Unfortunately, I haven't been able to track down the issue. Here's the OpportunityWS apex class that I've updated since last edit:  global class OpportunityWS{ webservice static void createAsset(Id opportunityId) {     List&lt;Asset&gt; a = new List&lt;Asset&gt;();     List&lt;Opportunity&gt; o = [SELECT Supplier__c, Accountid FROM Opportunity WHERE Id = :opportunityId];     List&lt;OpportunityLineItem&gt; oli = [SELECT Product2Id, Product_Name__c FROM OpportunityLineItem WHERE Id = :opportunityId];      a.add( new Asset(         PSI_Supplier__c = o[0].Supplier__c,         PSI_Opportunity__c = oli[0].Product2Id,         AccountId = o[1].Accountid,         Name = oli[0].Product2Id,         Product2Id = oli[0].Product2Id,         Product_Name__c = oli[1].Product_Name__c         ));             insert a; }   }
89673
I am trying to get  to work within salesforce visualforce pages.  I have a basic vf page from  example, but it does not respopnd, I suspect there may be some "unknown" workaround needed? Does anyone know?  &lt;apex:page standardController="Contact" showHeader="false" sidebar="false" docType="html-5.0"  standardStylesheets="false"&gt;  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"&gt;&lt;/script&gt;      &lt;div id="the-basics"&gt;   &lt;input class="typeahead" type="text" placeholder="States of USA"/&gt; &lt;/div&gt;  &lt;script&gt;     var substringMatcher = function(strs) {       return function findMatches(q, cb) {         var matches, substrRegex;          // an array that will be populated with substring matches         matches = [];          // regex used to determine if a string contains the substring `q`         substrRegex = new RegExp(q, 'i');          // iterate through the pool of strings and for any string that         // contains the substring `q`, add it to the `matches` array         $.each(strs, function(i, str) {           if (substrRegex.test(str)) {             // the typeahead jQuery plugin expects suggestions to a             // JavaScript object, refer to typeahead docs for more info             matches.push({ value: str });           }         });          cb(matches);       };     };      var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',       'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',       'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',       'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',       'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',       'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',       'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',       'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',       'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'     ];      $('#the-basics .typeahead').typeahead({       hint: true,       highlight: true,       minLength: 1     },     {       name: 'states',       displayKey: 'value',       source: substringMatcher(states)     }); &lt;/script&gt;
366
Let's say we have this code for a LWC:  &lt;!-- helloExpressions.html --&gt; &lt;template&gt;     &lt;div class="slds-m-around_medium"&gt;         &lt;lightning-input name='firstName' label="First Name" onchange={handleChange}&gt;&lt;/lightning-input&gt;         &lt;lightning-input name='lastName' label="Last Name" onchange={handleChange}&gt;&lt;/lightning-input&gt;         &lt;p class="slds-m-top_medium"&gt;Uppercased Full Name: {uppercasedFullName}&lt;/p&gt;     &lt;/div&gt; &lt;/template&gt;   and this is the JS file:  // helloExpressions.js import { LightningElement, track } from 'lwc';  export default class HelloExpressions extends LightningElement {     @track firstName = '';     @track lastName = '';      handleChange(event) {         const field = event.target.name;         if (field === 'firstName') {             this.firstName = event.target.value;         } else if (field === 'lastName') {             this.lastName = event.target.value;         }     }      get uppercasedFullName() {         return `${this.firstName} ${this.lastName}`.toUpperCase();     } }   firstName and lastName have been decorated with @track. Now as per the documentation, decorating a property with @track makes it private and reactive, while to mark a property public and reactive, use @api.  So if I just change the decorator to @api for both these variables, it should work. I am referring these from the same component only. But it's not working.  UPDATE: 27th Feb -------------------- Somehow it's working today. I just changed the decorator of the variables to api.  import { LightningElement, api } from 'lwc';  export default class HelloExpressions extends LightningElement {     @api firstName = '';     @api lastName = '';      handleChange(event) {         const field = event.target.name;         if (field === 'firstName') {             this.firstName = event.target.value;         } else if (field === 'lastName') {             this.lastName = event.target.value;         }     }      get uppercasedFullName() {         return `${this.firstName} ${this.lastName}`.toUpperCase();     } }   So it's working.
56399
I have 2 components. VariationComponent and PGP_Tab_bar_item. I create PGP_Tab_bar_item in the markup of VariationComponent . Want to perform some action on PGP_Tab_bar_item if event is fired from PGP_Tab_bar_item component.  I am using component.find({instancesOf:}) but it is giving an empty Array[].  VariationComponent :  &lt;aura:attribute name="projects" type="Project__c[]" /&gt;  &lt;ul class="slds-tabs--default__nav" role="tablist"&gt; &lt;aura:iteration items="{!v.projects}" var="project" indexVar="index"&gt;     &lt;c:PGP_Tab_bar_item project="{!project}" isProgramme="false" variationId="{!v.variationId}" active="false"/&gt; &lt;/aura:iteration&gt; &lt;/ul&gt;  &lt;ui:button label="Save" press="{!c.handlePGPTab}" class="slds-button slds-button--brand" aura:id="handle" /&gt;   Controller:  handlePGPTabEvent : function(component, event, helper){     var tabs = component.find({ instancesOf : "c:PGP_Tab_bar_item" }) ;     console.log(tabs); // output Array[] in console }
113588
I'm trying to get an event to fire whenever a choice is made from a JComboBox.  The problem I'm having is that there is no obvious addSelectionListener() method.  I've tried to use actionPerformed(), but it never fires.  Short of overriding the model for the JComboBox, I'm out of ideas.  How do I get notified of a selection change on a JComboBox?**  Edit: I have to apologize. It turns out I was using a misbehaving subclass of JComboBox, but I'll leave the question up since your answer is good.
112886
I am building a menu component.  One menu-item is a sub-menu with list of opportunities, this list is created with aura:iteration over a list of opportunities.  When selecting a menu or a sub-menu, I need to make it look selected (change css attribute). For this to happen, I need to find this menu item in my controller.  If I add id attribute to my item markup and use the event attribute on my controller (event.currentTarget.id), I can catch the item itself and change it's style, this works:  MARKUP       &lt;aura:iteration items="{!v.opportunities}" var="opp"&gt;     &lt;li class="slds-dropdown__item" role="presentation"&gt;         &lt;a href="javascript:void(0);" role="menuitem" tabindex="-1" id="{!opp.Id}" onclick="{!c.openItemFromMenu}"&gt;             &lt;span class="slds-truncate" title="{!opp.Name}"&gt;{!opp.Name}&lt;/span&gt;         &lt;/a&gt;     &lt;/li&gt; &lt;/aura:iteration&gt;   CONTROLLER    openItemFromMenu: function(component, event, helper) {     // get the id     var oppId = event.currentTarget.id;     // choose it (select menu)     var selectedItemNew = component.find(oppId);     selectedItemNew.style = "background: rgb(216, 237, 255);" }   PROBLEM  when I try to change the menu selected not from the click of the item (event that is triggered from another page) - I have added an event handler to change the menu item, and I send the opportunity id through that event. Then (after adding aura:id to my item, I am trying to find this menu item of this oppId with component.find in my controller - this does not work:  CHANGED MARKUP  add: &lt;aura:handler name="eventSelectMenuItem" event="c:myEvent" action="{!c.openItemFromMenu}" /&gt; change: &lt;a href="javascript:void(0);" role="menuitem" tabindex="-1" id="{!opp.Id}" onclick="{!c.openItemFromMenu}" aura:id="{!opp.Id}"&gt;   CHANGED CONTROLLER  openItemFromMenu: function(component, event, helper) {     // get the id from the event     var oppId = event.getParam("recordId");     // choose it (select menu)     var selectedItemNew = component.find(oppId);     selectedItemNew.style = "background: rgb(216, 237, 255);" }   QUESTION  Does component.find for aura:id within an aura:iteration suppose to work?  If not - is there a workaround?  If it does suppose to work - what am I doing wrong?
49311
I want to refresh the entire service console on clicking of the save button on the visual force page. The button is an inline visual force page. Any ideas?  &lt;apex:includeScript value="/soap/ajax/26.0/connection.js"/&gt; &lt;apex:includeScript value="/support/console/26.0/integration.js"/&gt; &lt;script type="text/javascript"&gt; function focusAndSave() {     document.getElementById('focusMe').click(); }     &lt;/script&gt;     &lt;apex:form &gt;     &lt;apex:pageBlock id="pb"&gt;         &lt;apex:pageMessages id="errMsgsId"&gt;&lt;/apex:pageMessages&gt;         &lt;input type="text" id="focusMe" style="display:none" /&gt;         &lt;apex:pageBlockTable id="table" value="{!candidateMap}" var="c"&gt;             &lt;apex:column value="{!candidateMap[c].Contact__r.Name}"/&gt;             &lt;apex:column value="{!candidateMap[c].Submitted_at__c}"/&gt;             &lt;apex:column value="{!candidateMap[c].Interview_Availability__c}"/&gt;             &lt;apex:column value="{!candidateMap[c].Notice_Available__c}"/&gt;             &lt;apex:column headervalue="Stage"&gt;                 &lt;apex:outputfield value="{!candidateMap[c].Stage__c}"&gt;                     &lt;apex:inlineEditSupport event="ondblclick"/&gt;                 &lt;/apex:outputfield&gt;             &lt;/apex:column&gt;             &lt;apex:column headervalue="Ideally looking for"&gt;                 &lt;apex:outputfield value="{!candidateMap[c].Ideally_looking_for__c}"&gt;                     &lt;apex:inlineEditSupport event="ondblclick"/&gt;                 &lt;/apex:outputfield&gt;             &lt;/apex:column&gt;             &lt;apex:column headervalue="Action"&gt;                 &lt;apex:commandLink value="Save" action="{!saveCandidate}" rerender="errMsgsId,table" onclick="focusAndSave()" oncomplete="testGetFocusedPrimaryTabId()"&gt;                     &lt;apex:param name="candidateId" value="{!candidateMap[c].Id}" assignTo="{!candidateId}"/&gt;                 &lt;/apex:commandLink&gt;             &lt;/apex:column&gt;         &lt;/apex:pageBlockTable&gt;         &lt;apex:panelGrid columns="7" style="margin: 0 auto;"&gt;             &lt;apex:outputLabel value="{!noOfRecords} records found"&gt;&lt;/apex:outputLabel&gt;             &lt;apex:commandButton status="fetchStatus" reRender="pb" value="|&lt;" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/&gt;             &lt;apex:commandButton status="fetchStatus" reRender="pb" value="&lt;" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/&gt;             &lt;apex:commandButton status="fetchStatus" reRender="pb" value="&gt;" action="{!next}" disabled="{!!hasNext}" title="Next Page"/&gt;             &lt;apex:commandButton status="fetchStatus" reRender="pb" value="&gt;|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/&gt;             &lt;apex:outputLabel value="Page {!pageNumber} of {!pagecount}"&gt;&lt;/apex:outputLabel&gt;         &lt;/apex:panelGrid&gt;     &lt;/apex:pageBlock&gt; &lt;/apex:form&gt;
57041
Can someone explain me, why object binding is not working?  cmpOne.cmp  &lt;aura:component extensible="true" abstract="true" access="global"&gt;     &lt;aura:attribute name="testObject" type="Account" access="global"/&gt;      &lt;span&gt;         {!v.body}     &lt;/span&gt; &lt;/aura:component&gt;   cmpOneFirst.cmp  &lt;aura:component extends="c:cmpOne" access="global"&gt;       &lt;ui:inputText value="{!v.testObject.Name}" /&gt;  &lt;/aura:component&gt;   cmpOneSecond.cmp  &lt;aura:component extends="c:cmpOne" access="global"&gt;     &lt;aura:attribute name="types" type="Aura.Component[]" access="global"/&gt;     {!v.types} &lt;/aura:component&gt;   cmpOneThird.cmp  &lt;aura:component extends="c:cmpOne" access="global"&gt;     // value of field should be changed, as  this value  is changing  in  inner component     {!v.testObject.Name} &lt;br/&gt;       &lt;c:cmpOneSecond&gt;         &lt;aura:set attribute="types"&gt;             &lt;c:cmpOneFirst testObject="{!v.testObject}"/&gt;         &lt;/aura:set&gt;     &lt;/c:cmpOneSecond&gt; &lt;/aura:component&gt;   No controllers.   Desired behaviour: when  you change value of  name field in cmpOneFirst.cmp, new value is displayed in cmpOneThird.cmp   If you change type of testObject attribute from Account to String - binding works.  Any suggestions?
37619
EDIT Dec 4 -  We're doing it live! Please post bugs or concerns as questions tagged [top-bar]  We have rolled out our 95% completed top bar for feedback.  Note:   We are still adding a few final features, so if you have a request for a feature that is not there you might hold off on that for a day or two Yes, the bar is black1. Also give that a day or two to sink in.   I also want to specifically address the meta/main/chat links.  I'm very aware that many of you like having the links at the top of the page and that this new version is different.  The thought process behind moving these links is that the "site switcher" should be an automatic place to go when you are on a site and want to go to another one. If you haven't already developed the muscle memory for these links, getting between them required a bit of a cognitive load: You must first decide that you want to switch sites and then you have to decide which area to go to to switch.  Also, we find that less familiar users aren't entirely clear what a standalone link that says "main" or "meta" actually does... Not to mention that it hurts my UX sensibilities that we are dynamically changing links in an element that should be fixed.  It is true that we have added a click in the process, but we have also removed a lot of clicks for other common actions that are much more frequent than switching between main and meta.  All I ask is that you give it a few days and see if the new "switch sites at the top left" paradigm grows on you.  What do you think?  1.  points out that technically it's not quite black.
31400
I'm trying to capture the display css property value for an element. However, unless I set style.display value in js it doesn't work. HTML: &lt;div class =&quot;dropdown slds-size_1-of-4&quot; &gt;    &lt;p&gt;A&lt;/p&gt;    &lt;p&gt;B&lt;/p&gt;    &lt;p&gt;C&lt;/p&gt; &lt;/div&gt;  CSS: .dropdown{     position: absolute;     display: none;     background: white; }  JS: Below JS method is be called from one of the input boxes in html: updateDropDownStyle(){    console.log('display : '   ,this.template.querySelector('.dropdown').style.display); }  However, the console prints nothing at all. However, if in the same method I set the element.style.display value as none and then try to console the above - it prints none. What's the issue here?
72166
I have some HTML and jQuery that slides a div up and down to show or hide` it when a link is clicked:  &lt;ul class="product-info"&gt;   &lt;li&gt;     &lt;a href="#"&gt;YOU CLICK THIS TO SHOW/HIDE&lt;/a&gt;     &lt;div class="toggle"&gt;       &lt;p&gt;CONTENT TO SHOW/HIDE&lt;/p&gt;     &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;   $('div.toggle').hide(); $('ul.product-info li a').click(function(event){   $(this).next('div').slideToggle(200); }   My question is: How do I use preventDefault() to stop the link acting as a link and adding "#" to the end of my URL &amp; jumping to the top of the page?  I can't figure out the right syntax, I just keep getting an error saying      preventDefault() is not a function.
87646
Salesforce has functions that do a lot of basic web app functionality for you, called Event Reference. They can be found here   On the editRecord Event Reference, found here   essentaily, I create a   &lt;ui:button label="Edit" press="{!c.editRecord}"/&gt;   on my component, reference the attribute on the page and add the function from the docs in the controller  editRecord : function(component, event, helper) {     var editRecordEvent = $A.get("e.force:editRecord");      console.log("record id is: " + component.get("v.item.Id"));     console.log("editRecordEvent value is: " + editRecordEvent);      editRecordEvent.setParams({         "recordId": component.get("v.item.Id")     });      editRecordEvent.fire(); }   correct?  Here is the odd thing. From the console.logs, I get the record id, but the editRecordEvent returns undefined. What is going on? Is there something I need to reference in my component to use Event Reference?
49150
Is there a way to catch the change event of a particular field/component? I saw on the AuraDocs that there is a valueChange event but trying to handle it makes the app throw an error on load. I was wondering if I could build some automatic field validation / search suggestions without relying on other js libraries.
27357
In my experience, input type="text" onchange event usually occurs only after you leave (blur) the control.  Is there a way to force browser to trigger onchange every time textfield content changes? If not, what is the most elegant way to track this “manually”?  Using onkey* events is not reliable, since you can right-click the field and choose Paste, and this will change the field without any keyboard input.  Is setTimeout the only way?.. Ugly :-)
92658
I'm using Jquery's toggle event to do some stuff when a user clicks a checkbox, like this:  $('input#myId').toggle( function(){ //do stuff   }, function(){ //do other stuff     } );   The problem is that the checkbox isn't being ticked when I click on the checkbox. (All the stuff I've put into the toggle event is working properly.)  I've tried the following:  $('input#myId').attr('checked', 'checked');   and  $(this).attr('checked', 'checked');   and even simply  return true;   But nothing is working. Can anyone tell me where I'm going wrong?  Edit - thanks to all who replied. Dreas' answer very nearly worked for me, except for the part that checked the attribute. This works perfectly (although it's a bit hacky)  $('input#myInput').change(function () {     if(!$(this).hasClass("checked"))     {         //do stuff if the checkbox isn't checked         $(this).addClass("checked");         return;     }      //do stuff if the checkbox isn't checked     $(this).removeClass('checked'); });   Thanks again to all who replied.