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
Alpana RawatAlpana Rawat 

how to enable checkbox when other checkboxes in the lightning component are checked?

i have 13 checkboxes when they all are check my final checkbox got enabled.
 
these 13 checkboxes i m showing aura:iteration
kindly help me here.
AbhishekAbhishek (Salesforce Developers) 
Hi,

Try the code as mentioned in the below blogs,

https://developer.salesforce.com/forums/?id=906F0000000AxGRIA0

https://salesforce.stackexchange.com/questions/244309/enable-button-when-checkbox-checked-in-lightning-component

I hope this information helps you.

 
sachinarorasfsachinarorasf
Hi Alpana Rawat,

I have gone through your problem. 

You can use the below code.

-:Aura Component:-

<aura:component >
    <aura:attribute type="List" name="checkBoxWrapper"/>
    <aura:attribute type="Boolean" name="finalCheckBox"  default="false"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <div>
        <lightning:input type="checkbox" label="Final checkbox" onchange="{!c.finalCheckbox}" value="{!v.finalCheckBox}"/>
        <aura:iteration items="{!v.checkBoxWrapper}" var="checkBox">
            <lightning:input type="checkbox" value="" onchange="{!c.onchengeCheck}" checked="{!checkBox.checkBox}"/>
        </aura:iteration>
    </div>
    
</aura:component>

-:Controller:-

({
    doInit : function(c, e, h) {
        var checkBoxWrapper = [];
        for(var i=0; i<13; i++){
            var checkBoxWrapperObject = {};
            checkBoxWrapperObject.checkBox = false;
            checkBoxWrapper.push(checkBoxWrapperObject);
        }
        c.set('v.checkBoxWrapper', checkBoxWrapper);
    },
    finalCheckbox : function(c, e, h){
        var isChacked = e.getSource().get('v.checked');
        if(isChacked){
            var checkBoxWrapper = [];
            for(var i=0; i<13; i++){
                var checkBoxWrapperObject = {};
                checkBoxWrapperObject.checkBox = 'True';
                checkBoxWrapper.push(checkBoxWrapperObject);
            }
            c.set('v.checkBoxWrapper', checkBoxWrapper);
        }else{
            var checkBoxWrapper = [];
            for(var i=0; i<13; i++){
                var checkBoxWrapperObject = {};
                checkBoxWrapperObject.checkBox = false;
                checkBoxWrapper.push(checkBoxWrapperObject);
            }
            c.set('v.checkBoxWrapper', checkBoxWrapper);
        }
        
    },
    onchengeCheck : function(c, e, h){
        
    },
})


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora