mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-09 10:54:11 -04:00
fix being able to add template without selecting a radio button
This commit is contained in:
@@ -1151,17 +1151,17 @@ def required_for_ops(*operations):
|
||||
operations = set(operations)
|
||||
|
||||
def validate(form, field):
|
||||
if form.op not in operations and field.data:
|
||||
if form.op not in operations and any(field.raw_data):
|
||||
# super weird
|
||||
raise ValidationError('Must be empty')
|
||||
if form.op in operations and not field.data:
|
||||
raise ValidationError('Can’t be empty')
|
||||
raise validators.StopValidation('Must be empty')
|
||||
if form.op in operations and not any(field.raw_data):
|
||||
raise validators.StopValidation('Can’t be empty')
|
||||
return validate
|
||||
|
||||
|
||||
class TemplateAndFoldersSelectionForm(Form):
|
||||
"""
|
||||
This form also expects the form data to include an operation, based on which submit button is clicked.
|
||||
This form expects the form data to include an operation, based on which submit button is clicked.
|
||||
If enter is pressed, unknown will be sent by a hidden submit button at the top of the form.
|
||||
The value of this operation affects which fields are required, expected to be empty, or optional.
|
||||
|
||||
@@ -1248,6 +1248,6 @@ class TemplateAndFoldersSelectionForm(Form):
|
||||
move_to_new_folder_name = StringField('Folder name', validators=[required_for_ops('move-to-new-folder')])
|
||||
|
||||
add_template_by_template_type = RadioField('Add new', validators=[
|
||||
required_for_ops('add-new-template'),
|
||||
Optional(),
|
||||
required_for_ops('add-new-template')
|
||||
])
|
||||
|
||||
@@ -130,6 +130,9 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
|
||||
except Exception as e:
|
||||
flash(e.message)
|
||||
|
||||
if 'templates_and_folders' in templates_and_folders_form.errors:
|
||||
flash('Select at least one template or folder')
|
||||
|
||||
return render_template(
|
||||
'views/templates/choose.html',
|
||||
current_template_folder_id=template_folder_id,
|
||||
|
||||
@@ -959,6 +959,10 @@ def test_should_be_able_to_move_a_sub_item(
|
||||
'move_to': '__NONE__',
|
||||
'add_template_by_template_type': 'email',
|
||||
},
|
||||
# add a new template, but don't select anything
|
||||
{
|
||||
'operation': 'add-new-template',
|
||||
},
|
||||
])
|
||||
def test_no_action_if_user_fills_in_ambiguous_fields(
|
||||
client_request,
|
||||
|
||||
Reference in New Issue
Block a user