enhance: detect duplicate input ids in lab guide questions#284
Merged
Conversation
parseLabGuide() already rejects duplicate question `name`s, but radio and
checkbox options legitimately repeat a name (they form one group) while
each option must still carry a unique `id` — the "Add checkbox question"
button emits `id`/`<label for="...">` pairs, and duplicate ids silently
break those associations so only the first matching option reacts to a
label click.
Add an independent id-uniqueness pass in the same preview loop: any input
with a repeated id is collected (deduplicated), highlighted red, and the
form is aborted with a "Duplicated input id found: ..." message shown
alongside the existing duplicate-name message.
Extend the jsdom regression suite (tests/js/parseLabGuide.test.js): the
per-case expectation is now { name, id } so a case can assert which
message fires. Adds duplicate-id cases (within a group, ids reused across
groups, checkbox groups, distinct-name text inputs, combined name+id) and
legitimate groups with unique ids. Verified the new cases fail against the
pre-change template and 25/25 pass after.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extends
parseLabGuide()inapps/templates/pages/labs_edit.htmlto also reject the lab-guide form when two inputs share the sameid, in addition to the existing duplicate-namecheck.Why
radio/checkbox options legitimately repeat their
name(they form a single option group), so the name check intentionally allows that. But each option must still have a uniqueid— the Add checkbox question button emits<input id="idN-1"> <label for="idN-1">pairs, and a duplicateidsilently breaks the label association so only the first matching option responds to a label click. Duplicate ids can arise e.g. when a question block is copied or two groups end up with the same id prefix.Change
An independent id-uniqueness pass runs in the same preview loop (before the name logic, so it also covers inputs missing a
name):Duplicated question name found: ...Duplicated input id found: ...questionCounteris unchanged (still counts unique names).Tests
tests/js/parseLabGuide.test.js— the per-case expectation is now{ name, id }so a case can assert exactly which message fires. Added cases:The function is extracted from the template at test time (not copied), so it guards the shipped code. Confirmed the new id cases fail against the pre-change template; 25/25 pass after the change.
Reviewer notes
namefix from fix: detect duplicate question names involving select boxes #273 (already merged tomain); this branch is cut from currentmainand contains only the id-detection commit.