manager: fix custom field form (#69467)

This commit is contained in:
Lauréline Guérin 2022-09-22 19:21:08 +02:00
parent 16fcb7d4df
commit 2a2112ceac
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 7 additions and 1 deletions

View File

@ -399,7 +399,7 @@ class CustomFieldForm(forms.Form):
if cleaned_data.get('varname') and not cleaned_data.get('label'):
self.add_error('label', _('This field is required.'))
if cleaned_data.get('varname') and not cleaned_data.get('field_type'):
self.add_error('field', _('This field is required.'))
self.add_error('field_type', _('This field is required.'))
return cleaned_data

View File

@ -67,8 +67,14 @@ def test_edit_events_type_custom_fields(app, admin_user):
resp = app.get('/manage/events-type/%s/edit/' % events_type.pk)
resp.form['form-0-varname'] = 'foo'
resp.form['form-0-label'] = 'Foo'
resp = resp.form.submit()
assert resp.context['formset'][0].errors['field_type'] == ['This field is required.']
resp.form['form-0-label'] = ''
resp.form['form-0-field_type'] = 'text'
resp = resp.form.submit()
assert resp.context['formset'][0].errors['label'] == ['This field is required.']
resp.form['form-0-label'] = 'Foo'
resp = resp.form.submit()
assert resp.status_code == 302
events_type.refresh_from_db()
assert events_type.custom_fields == [