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
niranjan eniranjan e 

hi guys i have doubt can u please clarify,my problem is to dynamically populate value to a picklist and to save the selected value in the database.Here i am getting the value in the picklist but while re·trieveing it in the controller to save it showerror

//component 
<aura:attribute name="Companys" type="Object[]"></aura:attribute>
 <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<ui:inputSelect label="Proviences" class="dynamic" aura:id="InputSelectDynamic" value="{!v.Companys}" change="{!c.onSelectChange}"> required="False">
      <aura:iteration items="{!v.Companys}" var="levels">
          <ui:inputSelectOption text="{!levels.value}" label="{!levels.label}"/>
        </aura:iteration>
//controller 
doInit : function(component, event, helper) {
        var action = component.get("c.getLeadStatus");
        var inputsel = component.find("InputSelectDynamic");
        var opts=[];
        action.setCallback(this, function(a) {
        for(var i=0;i< a.getReturnValue().length;i++){
            opts.push({"class": "optionClass", label: a.getReturnValue()[i], value: a.getReturnValue()[i]});
        }
        inputsel.set("v.Companys", opts);
        component.set("v.Companys",opts);
         });
    $A.enqueueAction(action); 
    },
onSelectChange : function(component, event, helper) {
    var selected = component.find("InputSelectDynamic").get("v.Companys");
         alert('tt'+ selected); /// here i get ttundefined 
     }
//Serverside controller 
 @AuraEnabled
public static List<String> getLeadStatus(){
List<String> options = new List<String>();
Schema.DescribeFieldResult fieldResult = company__c.Province__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for (Schema.PicklistEntry f: ple) {
    options.add(f.getLabel());
}
system.debug('asdf'+options);
return options;}
    
Best Answer chosen by niranjan e
Nayana KNayana K
onSelectChange : function(component, event, helper) {
    var selected = component.find("InputSelectDynamic").get("v.value");
         alert('tt'+ selected); /// here i get ttundefined 
     }

It should be v.value not v. Companys.

All Answers

Nayana KNayana K
onSelectChange : function(component, event, helper) {
    var selected = component.find("InputSelectDynamic").get("v.value");
         alert('tt'+ selected); /// here i get ttundefined 
     }

It should be v.value not v. Companys.
This was selected as the best answer
niranjan eniranjan e
Hi,
@Nayana K i have tried what u said but there is something extra attriubte to be include to hold the value selected and i was laging in it i supose and now it is working good thanks for the help