You need to sign in to do that
Don't have an account?
Javier Castro
Unable to set default value in a dynamic select field
Hi everyone, I am working on a Lightning Component which has a lightning select with its values fetched dynamically from a picklist field.
I found on the Internet this solution but it's not working for me
Someone can help me?
Regards and thanks in advance
<lightning:select aura:id="select" label="Estado de la cita" name="source" onchange="{!c.handleSelect}" class="slds-m-bottom_medium"> <option value="" disabled="true" text="-- Selecciona Estado --"/> <option value="Todos" text="Todos"/> <aura:iteration var="stat" items="{!v.statusList}"> <option value="{!stat}" text="{!stat}"/> </aura:iteration> </lightning:select>
I found on the Internet this solution but it's not working for me
doInit: function(cmp){ var action = cmp.get("c.getStatus"); action.setCallback(this, function(response) { var state = response.getState(); var statusList = response.getReturnValue(); if(state == "SUCCESS"){ cmp.set("v.statusList",statusList); window.setTimeout( $A.getCallback( function() { cmp.find("select").set("v.statusList", statusList[1]); })); } }); $A.enqueueAction(action); },The cmp.find recover the value I want but then that value it's not setted as default.
Someone can help me?
Regards and thanks in advance
What you have to do is fix your code like this sample:
Full code here:
Where {!v.vidaWrapper} is an attribute. Then I compare the value stored on field Produto__c with the resulting var of iteration.
Make sense to you?
Let me know if I can help you.
Regards.
All Answers
What you have to do is fix your code like this sample:
Full code here:
Where {!v.vidaWrapper} is an attribute. Then I compare the value stored on field Produto__c with the resulting var of iteration.
Make sense to you?
Let me know if I can help you.
Regards.
This solved my problem
I am also unable to set default value in a dynamic select field
Can anyone help me how to achieve this