andrewhathaway / Winterfell

Generate complex, validated and extendable JSON-based forms in React.
http://winterfell.andrewhathaway.net
MIT License
785 stars 116 forks source link

CheckboxInputOptions stores values from all checkbox questions #45

Closed zvibogen closed 8 years ago

zvibogen commented 9 years ago

I am having an issue that when I have numerous questions that use the input type checkboxOptionsInput the checked answers are added the state including one from previous questions, thereby causing the answer to include all checked boxes from all of the different questions that use an checkboxOptionsInput. I think it might be due to the fact that the constructor set the state to the props.value and when the state is updated it also resets the props.value.

andrewhathaway commented 8 years ago

Do any of your question IDs match across your config? If this is the case, it will cause issues.

xjlu commented 8 years ago

I can confirm this issue. Essentially, all selected values from the panel 1 are carried over to the next multi choice panel. And, even if I uncheck a value in the panel 1, the value is still carried over to the next panel.

An Example would be, Panel 1 has only one question Q1 with [a, b, c, d], and Panel 2 has only one question Q2 with [e, f, g, h, i, g]. Click a, b, c, then uncheck c. Q2 has [a, b]. After switching to Panel 2, click e, g. Now Q2 has [a, b, c, e, g]. And sometimes, Q1 will have all Q2's choices, too.

zvibogen commented 8 years ago

I ended up finding a solution to my issue. If you adjust the file Winterfell/dist/inputTypes/checkboxOptionsInput.js Line 22 from : value: this.props.value To: value: this.props.value.length > 0 ? this.props.value.slice(0) : []; it should solve this issue. I have to admit it was a little while back and I don't remember if that was the only change I needed to get it to work but I am pretty sure it was all that was needed.

xjlu commented 8 years ago

Thanks a lot. I was looking at the same line, too. Your changes did fix it by cloning the array so that it won't change the original props.value array. It's not a problem with other types of input because others are not objects.

andrewhathaway commented 8 years ago

Appreciate finding the issue and yes, the clone is what will fix this. I'll have to find some time to work in a fix, or maybe this can be pull requested. :)

andrewhathaway commented 8 years ago

Fixed in latest version (coming today).