React-bootstrap: Checkbox not returning checked value

Created on 16 May 2016  路  3Comments  路  Source: react-bootstrap/react-bootstrap

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

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings