From b64661d9d211a6972ae88f84746a339bacde40d5 Mon Sep 17 00:00:00 2001 From: Mathias Date: Tue, 7 Oct 2025 17:24:04 +0200 Subject: [PATCH 1/7] Only show help text if there are errors on registration form Ideally we'd like to use `Meta.help_texts` to override the help text fields but that only works on fields generated from models (see the note under: https://docs.djangoproject.com/en/5.2/topics/forms/modelforms/#overriding-the-default-fields --- packages/hidp/hidp/accounts/forms.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/hidp/hidp/accounts/forms.py b/packages/hidp/hidp/accounts/forms.py index 7061e642..15f1d873 100644 --- a/packages/hidp/hidp/accounts/forms.py +++ b/packages/hidp/hidp/accounts/forms.py @@ -59,6 +59,16 @@ class Meta: model = UserModel fields = (UserModel.USERNAME_FIELD,) + def __init__(self, *args, **kwargs) -> None: + super().__init__(*args, **kwargs) + + # only show helptext for password fields if there are any errors + # Errors appear on password2 field for some reason, + # so just disable help text on both + if not self.has_error("password1") and not self.has_error("password2"): + self.fields["password1"].help_text = "" + self.fields["password2"].help_text = "" + def _get_validation_exclusions(self): # Exclude email from model validation (unique constraint), # This will make the form valid even if the email is already in use. From 89dcb14c8edb31a2557f7b83f0bc2a7897ae3c49 Mon Sep 17 00:00:00 2001 From: Mathias Date: Tue, 7 Oct 2025 17:35:49 +0200 Subject: [PATCH 2/7] Show second password field help text Help text doesn't really have any bearing on the errors, got them mixed up I think. --- packages/hidp/hidp/accounts/forms.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/hidp/hidp/accounts/forms.py b/packages/hidp/hidp/accounts/forms.py index 15f1d873..4b6002ec 100644 --- a/packages/hidp/hidp/accounts/forms.py +++ b/packages/hidp/hidp/accounts/forms.py @@ -63,11 +63,8 @@ def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) # only show helptext for password fields if there are any errors - # Errors appear on password2 field for some reason, - # so just disable help text on both if not self.has_error("password1") and not self.has_error("password2"): self.fields["password1"].help_text = "" - self.fields["password2"].help_text = "" def _get_validation_exclusions(self): # Exclude email from model validation (unique constraint), From 09d90ad398a5d3e5d961a1db4a91efe0b8f85711 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 10 Oct 2025 12:07:57 +0200 Subject: [PATCH 3/7] Modify the user_creation_template to add a tooltip instead form code --- packages/hidp/hidp/accounts/forms.py | 7 -- .../accounts/forms/user_creation_form.html | 100 ++++++++++++++++++ 2 files changed, 100 insertions(+), 7 deletions(-) diff --git a/packages/hidp/hidp/accounts/forms.py b/packages/hidp/hidp/accounts/forms.py index 4b6002ec..7061e642 100644 --- a/packages/hidp/hidp/accounts/forms.py +++ b/packages/hidp/hidp/accounts/forms.py @@ -59,13 +59,6 @@ class Meta: model = UserModel fields = (UserModel.USERNAME_FIELD,) - def __init__(self, *args, **kwargs) -> None: - super().__init__(*args, **kwargs) - - # only show helptext for password fields if there are any errors - if not self.has_error("password1") and not self.has_error("password2"): - self.fields["password1"].help_text = "" - def _get_validation_exclusions(self): # Exclude email from model validation (unique constraint), # This will make the form valid even if the email is already in use. diff --git a/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html b/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html index 40143548..015715b1 100644 --- a/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html +++ b/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html @@ -1 +1,101 @@ {% extends 'hidp/includes/forms/base_form.html' %} +{% comment %} +the following is a modified version of /django/forms/templates/django/forms/div.html +{% endcomment %} + + +{{ errors }} +{% if errors and not fields %} +
{% for field in hidden_fields %}{{ field }}{% endfor %}
+{% endif %} +{% for field, errors in fields %} +
+ {% if field.use_fieldset %} +
+ {% if field.label %}{{ field.legend_tag }}{% endif %} + {% else %} + {% if field.label %}{{ field.label_tag }}{% endif %} + {% endif %} + + {% if field.name == "password1" %} +
+ + {% comment %} inline svg so stroke can pick up the "currentColor" {% endcomment %} + + + + + + + + + +
{% lorem 12 w %}
+
+ + {% elif field.help_text %} +
{{ field.help_text|safe }}
+ {% endif %} + + {{ errors }} + {{ field }} +{% if field.use_fieldset %}
{% endif %} + {% if forloop.last %} + {% for field in hidden_fields %}{{ field }}{% endfor %} + {% endif %} +
+{% endfor %} +{% if not fields and not errors %} + {% for field in hidden_fields %}{{ field }}{% endfor %} +{% endif %} From b88874a3742d43ddc7f56cba62b2347fc9c0a118 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 10 Oct 2025 12:26:34 +0200 Subject: [PATCH 4/7] Use include instead of extend on base_form This way the base_form can still be overridden by child templates while allowing those child templates like user_creation_form to still be overridden themselves. --- .../templates/hidp/accounts/forms/user_creation_form.html | 6 +++++- .../hidp/hidp/templates/hidp/includes/forms/base_form.html | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html b/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html index 015715b1..27e32652 100644 --- a/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html +++ b/packages/hidp/hidp/templates/hidp/accounts/forms/user_creation_form.html @@ -1,4 +1,7 @@ {% extends 'hidp/includes/forms/base_form.html' %} + +{% block form %} + {% comment %} the following is a modified version of /django/forms/templates/django/forms/div.html {% endcomment %} @@ -55,7 +58,7 @@ -
{% lorem 12 w %}
+
{{ field.help_text|safe }}