I have a checkbox and I'm trying to get the status of it. Everytime I toggle it returns true though. Am I doing this correctly?
<Checkbox onChange={this.setPermChange.bind(this)}>Admin Access</Checkbox>
setPermChange(e) { console.log( e.target.value ); } // returns 'on' every time
the value of checkboxes is what the value attribute is, use the checked property for whether it's checked or not
I'm loving your project. Amazing stuff. However, I am also having the same issue.
Like you suggested, I am checking the value attribute. However, like @mikejonas mentioned, target.value always return "on", and target.checked only toggles once (the user cannot check then uncheck, or vice-versa) and then always return the same value.
Can you please clarify your answer, @jquense ?
Thank you
I managed.
To clarify to other users, what I understood is that you need to use defaultChecked to set the initial value, the query target.checked from within onChange to retrieve the checked status.
Most helpful comment
I managed.
To clarify to other users, what I understood is that you need to use
defaultCheckedto set the initial value, the querytarget.checkedfrom withinonChangeto retrieve the checked status.