diff --git a/server/apps/users/forms.py b/server/apps/users/forms.py index 275ad71e..f43d7679 100644 --- a/server/apps/users/forms.py +++ b/server/apps/users/forms.py @@ -1,5 +1,11 @@ from django import forms +class SelectRequired(forms.Select): + # Disables items in the drop down list that have an empty value + # See https://docs.djangoproject.com/en/4.2/ref/forms/renderers/#built-in-template-form-renderers + # See also the ChoiceWidget.create_option() implementation in django/forms/widgets.py + option_template_name = "users/select_option_disable_empty.html" + class UserProfileForm(forms.Form): autistic_identifications = [ @@ -8,7 +14,7 @@ class UserProfileForm(forms.Form): ("no", "No"), ("unspecified", "Prefer not to say"), ] - autistic_identification = forms.ChoiceField(choices = autistic_identifications, widget = forms.Select(), + autistic_identification = forms.ChoiceField(choices = autistic_identifications, widget = SelectRequired(), label="Do you identify as autistic?", help_text="AutSPACEs is focusing on collecting and sharing the voices and lived experiences of autistic people, which is why this is a mandatory question. If you select prefer not to say your answers will be considered as coming from a non-autistic person, labeled as such and e.g. not used for research.", required=True) diff --git a/server/apps/users/templates/users/select_option_disable_empty.html b/server/apps/users/templates/users/select_option_disable_empty.html new file mode 100644 index 00000000..565560ac --- /dev/null +++ b/server/apps/users/templates/users/select_option_disable_empty.html @@ -0,0 +1 @@ +