Repository navigation
fix: count only answers on the path the respondent took - #216
Conversation
Show/hide rules read only answers of shown questions above them, so a hidden answer counts as none and a question can't hide itself. The store tracks the path through the form: jumps, back and the sent answers follow it, and answers of skipped questions stay in the form for a way back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PhilReinking
left a comment
There was a problem hiding this comment.
Changes at 8f2f166, CI green.
Checked beyond the PR text: on my own server I filled a form with a jump, a group rule, prefill and Back. The stored answers follow the path, Back brings earlier answers back, and a reload starts a new session with the prefill again. With 2000 questions a step takes about 23 ms (14 ms on main). One gap is left, see inline.
| continue; | ||
| } | ||
|
|
||
| if (state.payload[block.id]) { |
There was a problem hiding this comment.
A question a jump skipped still steers show/hide rules. Example: car = no jumps over brand, and dealer shows when brand = BMW. With ?brand=BMW in the link, or BMW typed before going back, dealer still shows and its answer is stored, but brand isn't. That's the mismatch this ticket fixes for hidden questions.
I'd count only answers on the path here:
const onPath = [...state.path, state.current];
// in the loop
if (state.payload[block.id] && onPath.includes(block.id)) {I tried it on my own server: dealer is skipped then, and jumps, Back and the group rule still work. Three older tests set payload without path and need the path in their setup. The changelog line could then say that a skipped answer no longer makes later questions show.
A question a jump skipped kept steering show/hide rules with its unsent answer, also a prefilled one. Rules now count an answer only when its question is on the path to the current one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PhilReinking
left a comment
There was a problem hiding this comment.
OK at 83bdb51, CI green.
The skipped-answer gap is fixed. On my own server, dealer no longer shows or gets stored when brand was skipped, and it still shows when BMW is on the path. A jump to a question that needs a skipped answer falls back to the next question, as for any hidden target, and the stored answers stay consistent.
The public form now sends only answers on the path the respondent really took. Show/hide rules ignore the answer of a hidden or skipped question, and a question a jump skipped no longer sends its answer, also when prefilled.
Fixes BITS-182
Heads-up: Back works differently on forms with jumps.
Tested: Vitest, lint and vue-tsc green. The 7 new tests fail on main; the test for forms without rules or jumps passes on both.
Not tested: by hand in a browser.
🤖 Generated with Claude Code