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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

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.

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.

2 participants