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
Heidi ApaHeidi Apa 

Inputselect undefined using find in lightning controller helper

Hi!

I have an error in a lightning component that I didnt have 2 weeks ago... I am trying to populate two input selects retrieving the values from apex, but when I try to find the input select I have the next error: [Cannot read property 'length' of undefined]

Component:
<ui:inputSelect aura:id="InputValueSelectDynamic" 
                                                                                class="slds-input dynamic"
                                                                                labelClass="slds-form-element__label"
                                                                                required="true"  
                                                                                />

Controller:
helper.getOptionsPicklist(component,"Value");

Helper:
getOptionsPicklist: function(component, valor) {
         component.set("v.mostrarSpinner", true);
         var action = component.get("c.getOptionsPicklist");
        action.setParams({
                    "valor": valor
                });
       
        var inputsel = component.find("Input"+valor+"SelectDynamic");
                  
        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]});
          
            }
     
            if(inputsel.length>0){
                 for(var j=0;j<inputsel.length;j++){
                 inputsel[j].set("v.options", opts);
            }
            }
            else{
                 inputsel.set("v.options", opts);
            }

the push of "opts" its done correctly from apex but the variable inputsel is "undefined".... Any idea of whats going on?

Thank you!!!!​​
Raj VakatiRaj Vakati
try like below
 
var val =        "Input"+valor+"SelectDynamic" ; 
var inputsel = component.find(val);

 
Heidi ApaHeidi Apa
Thank you Raj V, but not working either :(