From 15db8d8cf59d364e21a226fdf477869c9894bdf9 Mon Sep 17 00:00:00 2001 From: Maximilian Haye Date: Mon, 16 Dec 2024 13:04:36 +0100 Subject: [PATCH] feat: add GeneratedIdElement See: questionpy-org/questionpy-sdk#140 --- questionpy_common/elements.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/questionpy_common/elements.py b/questionpy_common/elements.py index c0b5a1e..491cf0a 100644 --- a/questionpy_common/elements.py +++ b/questionpy_common/elements.py @@ -14,6 +14,7 @@ "CheckboxGroupElement", "FormElement", "FormSection", + "GeneratedIdElement", "GroupElement", "HiddenElement", "Option", @@ -167,6 +168,15 @@ 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 @@ -174,6 +184,7 @@ class RepetitionElement(_BaseElement): | HiddenElement | RadioGroupElement | RepetitionElement + | GeneratedIdElement | SelectElement | StaticTextElement | TextInputElement