Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Validation Summary component to edit template forms. #2028

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/templates/components/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
module=None,
show_validation_summary=False,
form=None,
field_order=None,
data_kwargs={}
) %}
<form
Expand All @@ -26,7 +27,7 @@
novalidate
>
{% if show_validation_summary %}
{{ validation_summary(form) }}
{{ validation_summary(form, field_order) }}
{% endif %}
{{ caller() }}
</form>
Expand Down
17 changes: 15 additions & 2 deletions app/templates/components/validation-summary.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
{% macro validation_summary(form=None) %}
{% macro validation_summary(form=None, field_order=None) %}
{% if form and form.errors %}
<div role="alert" tabindex="-1" class="border-4 border-red focus:outline-yellow mb-gutter p-gutter space-y-gutterHalf" id="validation-summary" data-testid="validation_summary" autofocus>
<h2 class="heading-medium m-0">{{ _('There was a problem') }}</h2>
<ol class="list list-number list-outside m-0">
{% for field in form.errors %}
{# Get a list of error keys #}
{% set error_fields = form.errors.keys()|list %}
{% if field_order %}
{# Get the fields given the field order. #}
{% set ordered_fields = (field_order|list)|select('in', error_fields)|list %}
{# Get the remaining fields. #}
{% set remaining_fields = error_fields|reject('in', field_order)|list %}
{# Combine the ordered fields and the remaining fields. #}
{% set fields_to_display = ordered_fields + remaining_fields %}
{% else %}
{# If no field order is given, display all fields. #}
{% set fields_to_display = form.errors %}
{% endif %}
{% for field in fields_to_display %}
{% if form[field].type != 'HiddenField' %}
<li>
<a class="link:text-red text-red visited:text-red" href="#{{ field }}">
Expand Down
41 changes: 25 additions & 16 deletions app/templates/views/edit-email-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
back_link_aria_label=_('Back to template {}').format(template.name) if template else _('Back')
)
}}
{% call form_wrapper() %}

{% call form_wrapper(
show_validation_summary=True,
form=form,
field_order=['name', 'subject', 'template_content', 'template_category_id']
) %}
<div class="grid-row contain-floats md:flex my-gutterAndAHalf">
<div class="md:max-w-2/3 flex-1 px-gutterHalf mb-gutterHalf">
{{ task_shortcut(
description=_("You can put double brackets around a variable to insert custom&nbsp;content."),
link_url=gca_url_for('personalisation_guide'),
link_text=_("Guide: Send messages with custom content"),
icon="arrow-up-right-from-square"
)
}}
description=_("You can put double brackets around a variable to insert custom&nbsp;content."),
link_url=gca_url_for('personalisation_guide'),
link_text=_("Guide: Send messages with custom content"),
icon="arrow-up-right-from-square"
)}}
</div>
<div class="md:max-w-2/3 flex-1 px-gutterHalf mb-gutterHalf">
{{ task_shortcut(
description=_("You can insert formatting such as bolds&nbsp;and&nbsp;bullets."),
link_url=gca_url_for('formatting_guide'),
link_text=_("Guide: Insert email formatting"),
icon="arrow-up-right-from-square"
)
description=_("You can insert formatting such as bolds&nbsp;and&nbsp;bullets."),
link_url=gca_url_for('formatting_guide'),
link_text=_("Guide: Insert email formatting"),
icon="arrow-up-right-from-square"
)
}}
</div>
</div>
Expand All @@ -51,14 +54,20 @@
{{ textbox(form.name, width='w-full', hint=_('This will not show in the message. Use a name that helps you find the template when you need it.'), rows=10, testid="template-name") }}

{{ textbox(form.subject, width='w-full', highlight_tags=True, rows=2, hint=_("Tell recipients what the email is about. Try to use less than 10 words.", testid="template-subject")) }}

{{ template_content(form.template_content, form.text_direction_rtl) }}

<h2 class="heading-medium">{{ _('Template category') }}</h2>
{% call template_category(form.template_category_id, true if template_category_mode == 'expand' else false) %}
{{ select(form.template_category_id, hint=_('Template categories help improve delivery of your messages'), option_hints=template_category_hints, option_conditionals=other_category, testid="template-categories", use_aria_labelledby=false) }}
{{ select(
form.template_category_id,
hint=_('Template categories help improve delivery of your messages'),
option_hints=template_category_hints, option_conditionals=other_category,
testid="template-categories",
use_aria_labelledby=false
) }}
Comment on lines +62 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to avoid including code formatting changes that are unrelated to the actual change you are trying to make, since it makes the PR bigger than it needs to be. But maybe your editor is just doing this on its own?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I had to undo an earlier change as the AC for this story was changed a bit. And I couldn't quite get that section back to what it was exactly. And I'm also having some auto-formatting issues as well on html files... Maybe we should see if we can fix that at the container level by adding the correct extensions.

{% endcall %}

{% if current_user.platform_admin %}
{{ radios(form.process_type, hint=_('This is only manageable by platform admins'), use_aria_labelledby=false) }}
{% endif %}
Expand Down
21 changes: 12 additions & 9 deletions app/templates/views/edit-sms-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
back_link=url_for('main.view_template', service_id=current_service.id, template_id=template.id) if template else url_for('main.create_template', service_id=current_service.id, template_folder_id=template_folder_id),
back_link_aria_label=_('Back to template {}').format(template.name) if template else _('Back')
) }}

{% call form_wrapper() %}

{% call form_wrapper(
show_validation_summary=True,
form=form,
field_order=['name', 'template_content', 'template_category_id']
) %}
<div class="grid-row contain-floats md:flex my-gutterAndAHalf">
<div class="md:max-w-2/3 px-gutterHalf mb-gutterHalf">
{{ task_shortcut(
description=_("You can put double brackets around a variable to insert custom&nbsp;content."),
link_url=gca_url_for('personalisation_guide'),
link_text=_("Guide: Send messages with custom content"),
icon="arrow-up-right-from-square"
)
}}
description=_("You can put double brackets around a variable to insert custom&nbsp;content."),
link_url=gca_url_for('personalisation_guide'),
link_text=_("Guide: Send messages with custom content"),
icon="arrow-up-right-from-square"
) }}
Comment on lines +30 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a code formatting change?

</div>
</div>

<div class="grid-row contain-floats">
<div class="md:w-2/3 px-gutterHalf">
{{ textbox(form.name, width='w-full', hint=_('This will not show in the message. Use a name that helps you find the template when you need it.'), testid="template-name") }}
Expand All @@ -51,4 +53,5 @@ <h2 class="heading-medium">{{ _('Template category') }}</h2>
</div>
</div>
{% endcall %}

{% endblock %}
Loading