You need to sign in to do that
Don't have an account?
Alpana 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.
these 13 checkboxes i m showing aura:iteration
kindly help me here.
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.
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