0

I have ui:inputSelect with aura id. I am trying to set the value using aura id from controller.

 <td data-label="Learning Community" title="Learning Community">                            
                                <ui:inputSelect aura:id="lcapply" class="slds-input"
                                                labelClass="slds-form-element__label" value="{!n.Learning_Community__c}">            
                                    <ui:inputSelectOption text="Select Learning Community..."/>
                                    <aura:iteration items="{!v.lcs}" var="lc">
                                        <ui:inputSelectOption text="{!lc.Id}" label="{!lc.Name}" />
                                    </aura:iteration>
                                </ui:inputSelect>
                            </td>

Controller function:

onChangeLC : function(component,event,helper){
        var selectedLC = component.find("lc").get("v.value");        
        component.find("lcapply").set("v.value", selectedLC.toString());

        alert(selectedLC);
    }

I am getting this error, not sure what I am missing..:(

enter image description here

UPDATE:

<aura:attribute name="lcselect" type="String" default="Select Learning Community..."/>   
 <td data-label="Learning Community" title="Learning Community">

                                    <ui:inputSelect aura:id="lcapply" class="slds-input"
                                                    labelClass="slds-form-element__label" value="{!v.lcselect}">            
                                        <ui:inputSelectOption text="Select Learning Community..."/>
                                        <aura:iteration items="{!v.lcs}" var="lc">
                                            <ui:inputSelectOption text="{!lc.Id}" label="{!lc.Name}" />
                                        </aura:iteration>
                                    </ui:inputSelect>
                                </td>

Controller:

onChangeLC : function(component,event,helper){
        var selectedLC = component.find("lcValue").get("v.value");      
        component.set("v.lcselect", selectedLC.toString());    
    }
2

Assign a variable as you did with selectedLC, and then you can set a value by referencing the attribute.

The Lightning Components Developer Guide has a clear example on it:

({
    getLabel : function(component, event, helper) {
        var myLabel = component.find("button1").get("v.label");
        component.set("v.buttonLabel", myLabel);
    }
})

one more thing, make sure you have more than one element in your inputSelect list since there is this known issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.