function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prakhar KPrakhar K 

in lightning , how to get user selected value of dynamic picklist in controller ?

I have made a picklist having dynamic values of picklist but I am unable to get the user selected value in controller.When user selects any of the values ,a function called "showTemplateText" fires up and here I want to get the user selected value. Below is the Component code and Controller code .

Component Code Snippet:

<aura:attribute name="templates" type="Message_Template__c[]" />   //object of type  Message_Template__c//
<select id="msg-template" name="msg.id" style="width:200px;"  onchange="{!c.showTemplateText}" class="form-control is-filled" aria-invalid="false">
                        <option>--Select Msg Template--</option>   
                        <aura:iteration items="{!v.templates}" var="templ" >
                           <ui:inputSelectOption text="{!templ.Name}" />       //it shows value in front end but did not send any value at back end.any ideas?//
                        </aura:iteration>
            </select>
      ----------------------------------------------------------------------------------
   
function showTemplateText in controller

showTemplateText: function(component, event, helper){
var variable=component.get("v.templates[1].Text_Template__c");    //but using this i get a specific value no matter what i select in picklist.
}

-------------------------------------
 
Mohith Kumar ShrivastavaMohith Kumar Shrivastava
<!--Example of dynamic Input selection population-->

<div class="row">
<p class="title">Dynamic Option Generation</p>
<ui:inputSelect label="Select me: " class="dynamic" aura:id="InputSelectDynamic"
change="{!c.onChange}" />
<p>Selected Items:</p>
<p><ui:outputText class="result" aura:id="dynamicResult" value="" /></p>
</div>

The init function to populate value
 
({
doInit : function(cmp) {
// Initialize input select options
var opts = [
{ "class": "optionClass", label: "Option1", value: "opt1", selected: "true"
},
{ "class": "optionClass", label: "Option2", value: "opt2" },
{ "class": "optionClass", label: "Option3", value: "opt3" }
];
cmp.find("InputSelectDynamic").set("v.options", opts);
},

onChange: function(cmp, evt) {
var dynamicCmp = cmp.find("InputSelectDynamic");
resultCmp = cmp.find("dynamicResult");
resultCmp.set("v.value", dynamicCmp.get("v.value"));
}
})

So i guess in your case you should try using ui:inputSelect rather than normal Select .