mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 16:18:26 -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)
|
operations = set(operations)
|
||||||
|
|
||||||
def validate(form, field):
|
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
|
# super weird
|
||||||
raise ValidationError('Must be empty')
|
raise validators.StopValidation('Must be empty')
|
||||||
if form.op in operations and not field.data:
|
if form.op in operations and not any(field.raw_data):
|
||||||
raise ValidationError('Can’t be empty')
|
raise validators.StopValidation('Can’t be empty')
|
||||||
return validate
|
return validate
|
||||||
|
|
||||||
|
|
||||||
class TemplateAndFoldersSelectionForm(Form):
|
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.
|
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.
|
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')])
|
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=[
|
add_template_by_template_type = RadioField('Add new', validators=[
|
||||||
|
required_for_ops('add-new-template'),
|
||||||
Optional(),
|
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:
|
except Exception as e:
|
||||||
flash(e.message)
|
flash(e.message)
|
||||||
|
|
||||||
|
if 'templates_and_folders' in templates_and_folders_form.errors:
|
||||||
|
flash('Select at least one template or folder')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/templates/choose.html',
|
'views/templates/choose.html',
|
||||||
current_template_folder_id=template_folder_id,
|
current_template_folder_id=template_folder_id,
|
||||||
|
|||||||
@@ -959,6 +959,10 @@ def test_should_be_able_to_move_a_sub_item(
|
|||||||
'move_to': '__NONE__',
|
'move_to': '__NONE__',
|
||||||
'add_template_by_template_type': 'email',
|
'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(
|
def test_no_action_if_user_fills_in_ambiguous_fields(
|
||||||
client_request,
|
client_request,
|
||||||
|
|||||||
Reference in New Issue
Block a user