From 2a5cf9f6d040ae1914d47b539147a1d76e59d76c Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Mon, 28 Dec 2020 14:23:54 +0200 Subject: Add required field to question model --- backend/models/question.py | 1 + 1 file changed, 1 insertion(+) (limited to 'backend') diff --git a/backend/models/question.py b/backend/models/question.py index 3b98024..7daeb5a 100644 --- a/backend/models/question.py +++ b/backend/models/question.py @@ -12,6 +12,7 @@ class Question(BaseModel): name: str type: str data: dict[str, t.Any] + required: bool class Config: allow_population_by_field_name = True -- cgit v1.2.3 From 964e0757d5a070483bb75e1bcad48aff099e986b Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Mon, 28 Dec 2020 14:28:21 +0200 Subject: Add handling of optional fields to submit endpoint --- backend/routes/forms/submit.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'backend') diff --git a/backend/routes/forms/submit.py b/backend/routes/forms/submit.py index 8588a2d..d8e6d35 100644 --- a/backend/routes/forms/submit.py +++ b/backend/routes/forms/submit.py @@ -111,7 +111,10 @@ class SubmitForm(Route): missing_fields = [] for question in form.questions: if question.id not in response["response"]: - missing_fields.append(question.id) + if not question.required: + response["response"][question.id] = None + else: + missing_fields.append(question.id) if missing_fields: return JSONResponse({ -- cgit v1.2.3