Skip to content

Commit

Permalink
feat: add GeneratedIdElement
Browse files Browse the repository at this point in the history
  • Loading branch information
MHajoha committed Jan 7, 2025
1 parent 9b8612f commit 0670b0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 0670b0b

Please sign in to comment.