Component
<aura:attribute name="record" type="Customobject__c" />
<lightning:input type="checkbox" aura:id="test1" label="Complex Track"
value="{!v.record.Complex_Case__c}"
onchange="{!c.onValueChanged}"/><br/>
<lightning:input type="checkbox" aura:id="ftTrack" label="Fast Track"
value="{!v.record.Fast_Track_Case__c}" onchange="{!c.onValueChanged}"/><br/>
controller
onValueChanged{
//Trying to print the custom object record whether it is holding value, but //both of the below script return NULL
console.log(' value1 ', c.find('test1').get("v.value"));
console.log('record changed : ', JSON.stringify(c.get("v.record")));
}
I have to get the checked checkboxes in controller so that i can perform some validation on that.
Please help me to understand if I am missing something.
Best Answer
In HTML, and thus Aura/LWC frameworks, the
value
property of a checkbox is the value to submit to the server if the box is checked and you're using a form with a submit button. To determine if the checkbox is actually checked, use thechecked
attribute.Also, that means you need to bind to
checked
in your markup: