diff options
| author | 2020-12-28 21:36:53 +0000 | |
|---|---|---|
| committer | 2020-12-28 21:36:53 +0000 | |
| commit | 3b11fd104aac24d4b14d60babbae9afd58c8ee22 (patch) | |
| tree | 67c2ca29e0a709facd18fa18cb1d7714b72f24b0 | |
| parent | Fix deployment manifest (diff) | |
| parent | Add handling of optional fields to submit endpoint (diff) | |
Merge pull request #48 from python-discord/ks123/optional-questions
| -rw-r--r-- | backend/models/question.py | 1 | ||||
| -rw-r--r-- | backend/routes/forms/submit.py | 5 | 
2 files changed, 5 insertions, 1 deletions
| 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 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({ | 
