Skip to content

enhance: detect duplicate input ids in lab guide questions#284

Merged
italovalcy merged 1 commit into
mainfrom
fix/detect-duplicate-id
Jul 11, 2026
Merged

enhance: detect duplicate input ids in lab guide questions#284
italovalcy merged 1 commit into
mainfrom
fix/detect-duplicate-id

Conversation

@italovalcy

@italovalcy italovalcy commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

What

Extends parseLabGuide() in apps/templates/pages/labs_edit.html to also reject the lab-guide form when two inputs share the same id, in addition to the existing duplicate-name check.

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 unique id — the Add checkbox question button emits <input id="idN-1"> <label for="idN-1"> pairs, and a duplicate id silently 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):

  • tracks seen ids; a repeated id is collected once (deduplicated) and the input is highlighted red;
  • the form aborts if there is a duplicate name or a duplicate id, showing both messages:
    • Duplicated question name found: ...
    • Duplicated input id found: ...

questionCounter is 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:

  • duplicate id within a radio group, ids reused across two groups, duplicate id in a checkbox group, duplicate id on distinct-name text inputs, and a combined name+id case;
  • legitimate groups with unique ids (within one group and across two groups) that must not be flagged.

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.

cd tests/js && npm install && npm test

Reviewer notes

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>
@italovalcy italovalcy self-assigned this Jul 11, 2026
@italovalcy italovalcy changed the base branch from main to feat/lti-web-ui July 11, 2026 08:57
Base automatically changed from feat/lti-web-ui to main July 11, 2026 09:17
@italovalcy italovalcy marked this pull request as ready for review July 11, 2026 09:17
@italovalcy italovalcy merged commit dca6731 into main Jul 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant