mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-30 20:27:30 -04:00
Show flash instead of inline upload errors
This has several advantages: - It gives us more room to explain the error and actions. This will be useful for upcoming work we want to do, which will add yet more validations for CSV uploads. - We already use a flash to show certain kinds of errors on these pages (just above). This is more consistent. - It's potentially more accessible. Previously the error and the button text used to be read out as a single sentence. Now the page reloads and reads the flash error alone. In theory we should show an error in both places, but this can be confusing on pages where there's only a single form control, and especially if the error is long.
This commit is contained in:
@@ -175,6 +175,11 @@ def send_messages(service_id, template_id):
|
||||
).format(
|
||||
form.file.data.filename
|
||||
))
|
||||
elif form.errors:
|
||||
# just show the first error, as we don't expect the form to have more
|
||||
# than one, since it only has one field
|
||||
first_field_errors = list(form.errors.values())[0]
|
||||
flash(first_field_errors[0])
|
||||
|
||||
column_headings = get_spreadsheet_column_headings_from_template(template)
|
||||
|
||||
|
||||
@@ -417,6 +417,11 @@ def upload_contact_list(service_id):
|
||||
).format(
|
||||
form.file.data.filename
|
||||
))
|
||||
elif form.errors:
|
||||
# just show the first error, as we don't expect the form to have more
|
||||
# than one, since it only has one field
|
||||
first_field_errors = list(form.errors.values())[0]
|
||||
flash(first_field_errors[0])
|
||||
|
||||
return render_template(
|
||||
'views/uploads/contact-list/upload.html',
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
{{file_upload(
|
||||
form.file,
|
||||
allowed_file_extensions=allowed_file_extensions,
|
||||
button_text='Choose a file'
|
||||
button_text='Choose a file',
|
||||
show_errors=False
|
||||
)}}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
form.file,
|
||||
allowed_file_extensions=allowed_file_extensions,
|
||||
button_text='Choose file',
|
||||
show_errors=False,
|
||||
)}}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -279,7 +279,6 @@ def test_upload_csv_file_shows_error_banner_for_too_many_rows(
|
||||
def test_upload_csv_shows_error_with_invalid_extension(
|
||||
client_request,
|
||||
):
|
||||
|
||||
page = client_request.post(
|
||||
'main.upload_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
@@ -287,7 +286,7 @@ def test_upload_csv_shows_error_with_invalid_extension(
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
assert normalize_spaces(page.select_one('.file-upload-label .error-message').text) == (
|
||||
assert normalize_spaces(page.select_one('.banner-dangerous').text) == (
|
||||
"invalid.txt is not a spreadsheet that Notify can read"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user