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

GeneratedIdElement #126

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/qppe-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,17 @@ components:
minItems: 1
required: [ kind, name, initial_elements, increment, elements ]

GeneratedIdElement:
type: object
description: Generates a unique ID which won't change across form saves.
properties:
kind:
type: string
enum: [ id ]
name:
$ref: "#/components/schemas/FormName"
required: [ kind, name ]

FormElement:
oneOf:
- $ref: "#/components/schemas/StaticTextElement"
Expand All @@ -1440,6 +1451,7 @@ components:
- $ref: "#/components/schemas/HiddenElement"
- $ref: "#/components/schemas/GroupElement"
- $ref: "#/components/schemas/RepetitionElement"
- $ref: "#/components/schemas/GeneratedIdElement"

FormSection:
type: object
Expand Down
11 changes: 11 additions & 0 deletions questionpy_common/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"CheckboxGroupElement",
"FormElement",
"FormSection",
"GeneratedIdElement",
"GroupElement",
"HiddenElement",
"Option",
Expand Down Expand Up @@ -167,13 +168,23 @@ class RepetitionElement(_BaseElement):
"""Elements that will be repeated."""


class GeneratedIdElement(_BaseElement):
"""Generates a unique ID which won't change across form saves.

Useful to distinguish repetitions without relying on their index, which may change when repetitions are removed.
"""

kind: Literal["id"] = "id"


FormElement: TypeAlias = Annotated[
CheckboxElement
| CheckboxGroupElement
| GroupElement
| HiddenElement
| RadioGroupElement
| RepetitionElement
| GeneratedIdElement
| SelectElement
| StaticTextElement
| TextInputElement
Expand Down
Loading