0

All I want to do is retrieve picklist options from a custom object and fetch the inputSelect element in a lighning controller. I am trying this way.. but I am getting an error.. If someone knows any other way to achieve this goal I will appreciate a lot..

I get the following error when trying to return a List of strings to fetch a inputSelect with retrieved salesforce custom object data: Uncaught Error in $A.getCallback() [Cannot read property 'set' of undefined]

This is my code:

COMPONENT:

  <ui:inputSelect  aura:id="InputDDSelectDynamic" class="slds-select"  change="{!c.onPicklistChange}"/>

CONTROLLER JS in doInit function:

   helper.getOptionsPicklist(component,"DD");

HELPER JS:

    getOptionsPicklist: function(component, valor) {
    var action = component.get("c.getOptionsPicklist");
    action.setParams({
                "valor": valor
            });

    var inputsel = component.find("InputDDSelectDynamic");
     alert(inputsel);
    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.options", opts);


    });
    $A.enqueueAction(action);

}

APEX CONTROLLER:

      @AuraEnabled
public static List<String> getOptionsPicklist(String valor){
    List<String> options = new List<String>();
    String valorSF;
    Schema.DescribeFieldResult fieldResult;

    if(valor.equals('DD')){ //  
        fieldResult = QuoteLineItem.SpaceDD__c.getDescribe();
    }

    List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
    for (Schema.PicklistEntry f: ple) {
        options.add(f.getLabel());
    }

    return options;
}

**** The inputsel returns "undefined".... I dont know why, its like I cant get the inputSelect element...

Thank you!!!

1

Problem solved.... I was calling to the apex controller in the doInit function but this inputselect was not visible when the component was open, so I call apex controller once this part is visible with aura:if

Sorry and thank you!!

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.