andrewhathaway / Winterfell

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

When default value is set, it interferes with going back #109

Open KingMob opened 6 years ago

KingMob commented 6 years ago

I'm not sure what's happening, but I know it affects master. Visually, the correct radio option will be chosen, but any conditional questions that are supposed to appear based on it won't appear. The questionAnswers become incorrect when I go back, too, even though I didn't change the answer.

I can confirm that removing the default value fixes the issue, too. Without a default, the props and state match, but with a default, they don't have to.

andrewhathaway commented 6 years ago

Interesting, can you perhaps get a CodePen|Live version running so I can see exactly what you mean?

Thanks!

KingMob commented 6 years ago

Sure, check out https://codepen.io/KingMob/pen/paqmJZ

andrewhathaway commented 6 years ago

Hey @KingMob, having checked this out...this is kind of by design. Question IDs are not question set specific, they’re global. So when switching to the second panel, the default is set for the ID “first” question ID and when switching back, it will be set for the previous panel. Does that make sense?

KingMob commented 6 years ago

Uhh...not really. Why would the default for a question ever be used once I've chosen an actual answer? When people hit "back", they expect to see the same panel they just left.

andrewhathaway commented 6 years ago

Correct, but as the developer you should be having unique questionIds then this issue will be resolved. :)

KingMob commented 6 years ago

Ahh, I hadn't even noticed the CodePen questionId was duplicated. Unfortunately... I checked my real code, and there's no duplicate questionIds there.

I think I may have introduced a bug in the CodePen that's not related to the original issue. See this updated Codepen for an example where the conditional question doesn't appear when you go back: https://codepen.io/KingMob/pen/RMbVoM And if you comment out the default property, the conditional question appears correctly when going back.

(I suppose it's also possible I had two issues at once. E.g., some copy-and-paste and didn't notice I hadn't fully changed the copied question.)

andrewhathaway commented 6 years ago

Ah, okay this shows the bug! Reopening, CodePen v2 helps show the problem at hand.