Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check for duplicate input names #155

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

janbritz
Copy link
Contributor

@janbritz janbritz commented Feb 27, 2025

Damit wir im Plugin eindeutig Werte den Input-Feldern zuweisen können, sollten wir nur doppelte Namen bei checkbox- und radio-Elementen erlauben. Zusätzlich müssen dafür auch die Werte eindeutig sein.

Folgende formulation.xhtml.j2:

<div xmlns="http://www.w3.org/1999/xhtml" xmlns:qpy="http://questionpy.org/ns/question">

    <input type="checkbox" name="character" value="a" />
    <input type="checkbox" name="character" value="b" />
    <input type="text" name="character" />

</div>

Führt zu folgender Fehlermeldung:
image

Eigentlich könnten wir auch <button> und <input type="button" /> mit dem selben Namen und sogar selben Wert (value) erlauben, da wir im Plugin für diese Elemente keinen Wert setzen. Da dieser PR aber von diesem Issue entstammt, wollte ich diesen Teil nicht auch in diesem PR implementieren.

Copy link
Member

@MHajoha MHajoha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Danke 👍

other_element, values = name_map[name]
other_type = other_element.get("type", "text")

if current_type not in {"checkbox", "radio"}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So oder so nicht merkbar, aber aus akademischer Sicht: Für dieses Pattern ein Set zu verwenden hat ziemlich sicher mehr Overhead als du durch den O(1) lookup gewinnst. Für das Set müssen "checkbox" und "radio" z.B. erst gehasht werden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitiv, ich finde es so aber etwas cleaner.

Copy link
Contributor

@MartinGauk MartinGauk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Da nun #156 gemergt ist, kann dieser PR auch gerne gemergt werden.

@janbritz janbritz force-pushed the feat/check-for-duplicate-input-names branch from 3a3f24f to 47fd73b Compare April 3, 2025 11:05
@janbritz janbritz merged commit 69cac3c into dev Apr 3, 2025
7 checks passed
@janbritz janbritz deleted the feat/check-for-duplicate-input-names branch April 3, 2025 11:08
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.

3 participants