Skip to content

Commit

Permalink
Fix multiple checkbox errors on sample form
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-Crow committed Sep 17, 2024
1 parent c976696 commit e787cb5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@
{{ field|dsfr_input_class_attr|attr:"type:checkbox" }}
{% endif %}
{% if field.errors %}
<div id="{{ field.auto_id }}-desc-error" class="fr-error-text">
<div id="{{ field.auto_id }}-desc-error">
{{ field.errors }}
</div>
{% endif %}
</div>
</div>
{% if field.errors %}
<div id="{{ field.auto_id }}-messages">
{{ field.errors }}
</div>
{% endif %}
</fieldset>
4 changes: 2 additions & 2 deletions example_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ExampleForm(DsfrBaseForm):
widget=forms.RadioSelect,
)

sample_checkbox = forms.ChoiceField(
sample_checkbox = forms.MultipleChoiceField(
label="Cases à cocher",
required=False,
choices=[
Expand Down Expand Up @@ -124,7 +124,7 @@ def clean_sample_radio(self):
def clean_sample_checkbox(self):
sample_checkbox = self.cleaned_data["sample_checkbox"]

if sample_checkbox == ["2"]:
if "3" in sample_checkbox:
raise forms.ValidationError("Le troisième choix est interdit")

return sample_checkbox
Expand Down

0 comments on commit e787cb5

Please sign in to comment.