Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a checkbox with react throws a warning about an uncontrolled input becoming controlled #131

Closed
jdalegonzalez opened this issue Nov 25, 2016 · 0 comments
Labels

Comments

@jdalegonzalez
Copy link
Contributor

This issue is in SurveyQuestionCheckboxItem::render. The code:

var isChecked = this.question.value && this.question.value.indexOf(this.item.value) > -1;

sets isChecked to undefined, which means that the input created by SuveryQuestionCheckboxItem::renderCheckbox sets the checked attribute of the input item it creates to undefined. Having an undefined value for a checked attribute makes react decide that the item is uncontrolled. A later call to setState in SuveryQuestionCheckboxItem::handleOnChange makes react believe the input should be controlled and causes the warning to get thrown.

var isChecked = t(his.question.value && this.question.value.indexOf(this.item.value) > -1)||false;

prevents the warning - I'll issue a pull request for this change.

HOWEVER: I'm not enough of a react guru to know if the value for the checkbox is being handled correctly from a react perspective or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants