In my Lightning component I iterate over a custom wrapper to print a list of checkboxes on my page, now in my selectoptionvalue
I need to determine if the triggered checkbox was checked or unchecked. How can I do this?
Component
<input
aura:id="inputCheckbox"
onchange="{!c.selectoptionvalue}"
type="checkbox"
id="{!v.value}"
/>
Controller
({
selectoptionvalue : function(component, event, helper) {
console.log("isChecked:" + event.getSource().get("v.checked"));
...
I'm not sure I'm using the right string as nothing is returned in my console log if I use event.getSource().get("v.checked")
.
Best Answer
So it looks like
event.getSource().get("v.checked")
isn't available on the tags used. If I switch tolighting:input
it works as expected.In the end I used document.querySelector to get the element and check its value as I needed to input tags to support additional data attributes.
Something like this (note this is in a loop)