1

I have created a lightning component.But facing following error.

findvalue.get is not a function

    <aura:component >
    <aura:attribute name="Label" type="list"/>
    <ui:OutputURL label="Click" click="{!c.PopUp}" value=""/>
    <c:Editable aura:id="popup"> 
    <aura:set attribute="header">
  Select?
 </aura:set> 
 <aura:set attribute="content">
     <div class="slds-grid slds-wrap">         
         <aura:iteration items="{!v.Label}" var="lab">
              <div class="slds-p-horizontal--small slds-size--1-of-2">
                  <ui:inputCheckbox aura:id="check" label="{!lab}" value="" change="{!c.Change}"/>
             </div>
         </aura:iteration>
     </div>
    </aura:set>
     <aura:set attribute="footer"> <ui:button class="slds-button slds-button--neutral" press="{!c.Close}" label="Cancel"/> <ui:button class="slds-button slds-button--brand" press="{!c.Save}" label="Save"/></aura:set>
    </c:Editable>
</aura:component>

//Js controller
({
    PopUp : function(cmp, event, helper) {
        cmp.find("popup").open();
        var label=[];
        for(var i=1;i<=20;i++){
            label.push('label '+i);

        }
         cmp.set("v.Label",label);
       // alert(label);

    },
    Close : function(cmp, event, helper) {
       cmp.find("popup").close(); 
    },

    Save : function(cmp, event, helper) {        
      cmp.find("popup").close();
},
    Change : function(cmp, event, helper){
     var findvalue=cmp.find("check");
        var getvalue=findvalue.get("v.value");
        for(var i=1;i<=getvalue.length;i++){
        }
       alert(getvalue);

    }
})

The error is in Change function.It looks fine with syntax and all but i dont know what is happening wrong here. Any help would be appreciated.

1 Answer 1

4

The problem is that you are trying to find by aura:id, but your ui:inputCheckbox is inside an aura:iteration. So, trying to find a single component by the aura:id "check" won't work as there are lots of them and Lightning doesn't handle this scenario very well.

See also this question: How to assign dynamic Ids for ui:inputDate element inside aura:iteration?

For your purposes, you could make use of the event being passed into your Change function. You have:

var findvalue = cmp.find("check");

Instead, try using:

var findvalue = event.getSource();
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .