Skip to content

Commit

Permalink
Update form to not rely on the obsolete tag dsfr_form
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-Crow committed Aug 23, 2024
1 parent b52954f commit 51632c1
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
2 changes: 0 additions & 2 deletions config/forms/baseform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
class SitesFacilesBaseForm(DsfrBaseForm):
# Subclassing the Dsfr base form to set autofocus on the first error found when applicable

template_name = "dsfr/form_snippet.html"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.set_autofocus_on_first_error()
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ <h1>{% translate "Set your new password" %}</h1>
<form method="post" novalidate>
{% csrf_token %}

{% dsfr_form %}
{% dsfr_form_field form.new_password1 %}
{% dsfr_form_field form.new_password2 %}

<button type="submit" class="fr-btn">{% translate "Reset password" %}</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>{% translate "Reset your password" %}</h1>
<form method="post" novalidate>
{% csrf_token %}

{% dsfr_form %}
{% dsfr_form_field form.email %}

<button type="submit" class="fr-btn">{% translate "Reset password" %}</button>
</form>
Expand Down
2 changes: 1 addition & 1 deletion events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class EventSearchForm(SitesFacilesBaseForm):
"""Main form for search engine."""
"""Main form for events page list."""

date_from = forms.DateField(
label=_("From…"),
Expand Down
2 changes: 1 addition & 1 deletion forms/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class FormsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
default_auto_field = "django.db.models.BigAutoField" # type: ignore
name = "forms"
6 changes: 4 additions & 2 deletions forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ class Meta:
verbose_name_plural = _("Form fields")


class SitesFacilesBaseForm(BaseForm):
class SitesFacilesCustomForm(BaseForm):
"""
A base form that adds the necessary DSFR class on relevant fields
"""

template_name = "dsfr/form_snippet.html" # type: ignore

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for visible in self.visible_fields():
Expand All @@ -63,7 +65,7 @@ def create_datetime_field(self, field, options):
return forms.DateField(**options)

def get_form_class(self):
return type("WagtailForm", (SitesFacilesBaseForm,), self.formfields)
return type("WagtailForm", (SitesFacilesCustomForm,), self.formfields)


class FormPage(AbstractEmailForm):
Expand Down
2 changes: 1 addition & 1 deletion forms/templates/forms/form_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>{{ page.title }}</h1>
{{ page.intro|richtext }}
<form action="{% pageurl page %}" method="post">
{% csrf_token %}
{% dsfr_form %}
{{ form }}
<input class="fr-btn" type="submit">
</form>
</div>
Expand Down

0 comments on commit 51632c1

Please sign in to comment.