2

I have a dynamic checkbox generated trough an iterator.I want to be able to get the true and false values from the current state of the checkbox.

When ik check or uncheck my checkbox is always results in a true value as I would like to get the current state of the checkbock after selection.

Component

 <aura:attribute name="checkboxValue" type="Boolean" default="true" />

     <aura:handler name="change"
                  value="{!v.checkboxes}"
                  action="{!c.populateCheckboxes}"
                  description=""/>

   <aura:attribute name="records" type="object[]" description="" access="private" /> 
    <div style="width:100%" class="slds-align_absolute-left">
     {!v.objectName}
         <aura:iteration items="{!v.records}" var="item" indexVar="indx"> 
                 <ui:inputCheckbox aura:id="checkbox" 
                                   value="{!item.checkboxValue}" 
                                   text="{!item.fieldName}" 
                                   name="{!indx}" 
                                   label="{!item.fieldName}" 
                                   change="{!c.Techniek}"/>{#item.val}      
            </aura:iteration> 

Javascript

 if(component.get('v.checkboxValue') == true){
          console.log('test1');
        }

        if(component.get('v.checkboxValue') == false){
       console.log('test2');
    }
3

For the "ui:inputCheckbox" I would recommend you fetch the value using event.getSource(). Although the documentation seems to indicate you can use component.get('v.value'), however, the documented method seems to return 'undefined', therefore, you might want to check Event Handling in Base Lightning Components

So, in your function you will want to do:

var checkboxVale = event.getSource().get('v.value');
 if(checkboxVale == true){
//Do something
    }
else{
//Do something else
    }
  • Thx, has been driving me crazy but it works indeed this way. Thank you. – Thomas Jan 31 '18 at 2:06

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.