• Mike O.
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
The selected value in a list is not set as expected. The code in the .js controller is:
setListLocations : function(cmp, response) { 
     var list = response.getReturnValue().Locations;
     var locations = []; 
     for (var i=0; i< list.length; i++) { 
         var loc = {value: list[i], label: list[i]}; locations.push(loc); 
      } 
        cmp.set("v.locations", locations); 
        cmp.set("v.selectedValue", response.getReturnValue().Location); 
},
From what I have been reading the value is not set as the list is not ready at that time. 

In the component I have:
<lightning:select name="mySelect" onchange="{!c.getValue }" label="To" aura:id="mySelect" value="{!v.selectedValue}" >
         <aura:iteration items="{!v.locations}" var="item">
            <option value="{!item.value}" selected="{!item.selected}">
                {!item.label}
            </option>
        </aura:iteration>
    </lightning:select>
From what I have been reading the value is not set as the list is not ready at that time.

I used a time delay between creating the list and setting the selected value in the list and it seems to do the trick.
window.setTimeout(
                $A.getCallback(function() {
                    cmp.set("v.selectedValue", response.getReturnValue().Location);  
                }), 75
            );
However, I'm not quite happy with this solution. 

Is there another more elegant way of fixing  this issue?
I have the following in the component:
<lightning:input type="number" aura:id="input1" name="input1" value="1" required="true" />
In the controller.js I have an action that returns a value from the component controller.

I'd like to multiply this value with the number entered in "input1" and display it.

I do not seem able to read the value that is in "input1". I tried
alert('cmp.find(input1) = ', cmp.find('input1').get('v.value'));
and it shows an empty value.

thank you
 
Salesforce documentation about Calling a Server-Side Action (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm) has an example that contains:
 
if (state === "SUCCESS") {
 .......
        }
        else if (state === "INCOMPLETE") {
            // do something
        }
        else if (state === "ERROR") {
 ......
What should "do something" be?

I've seen so many examples with "do something", including the code I've been writing, that I'd thought I should stop doing this (copy/paste) and do something about it, pun intended.
 
I have the following in the component:
<lightning:input type="number" aura:id="input1" name="input1" value="1" required="true" />
In the controller.js I have an action that returns a value from the component controller.

I'd like to multiply this value with the number entered in "input1" and display it.

I do not seem able to read the value that is in "input1". I tried
alert('cmp.find(input1) = ', cmp.find('input1').get('v.value'));
and it shows an empty value.

thank you