manager: avoid validation errors on dynamic fields in cell edit form (#65163)

This commit is contained in:
Valentin Deniaud 2022-05-12 17:24:05 +02:00
parent b47c3e4219
commit ce0a65a35e
2 changed files with 5 additions and 2 deletions

View File

@ -713,9 +713,11 @@ class PageEditCellView(ManagedPageMixin, UpdateView):
for tab in self.object.get_manager_tabs():
if tab.get('fields'):
tab['form'] = forms.models.modelform_factory(self.object.__class__, fields=tab['fields'])
# if current form had no errors, create it anew
# if current form had no errors, create a new unbound form using current object
# so it can get new dynamic fields
form = tab_error_forms.get(tab['slug']) or tab['form'](**self.get_form_kwargs())
form = tab_error_forms.get(tab['slug']) or tab['form'](
instance=self.object, prefix=self.get_prefix(), initial={}
)
if tab['slug'] == 'general':
form_name = 'form'
else:

View File

@ -1625,6 +1625,7 @@ def test_chartng_cell_manager_new_api_dynamic_fields(app, admin_user, new_api_st
resp.form[field_prefix + 'statistic'] = statistic.pk
resp = app.post(resp.form.action, params=resp.form.submit_fields(), xhr=True)
assert 'time_interval' in resp.json['tabs']['general']
assert 'This field is required.' not in resp.json['tabs']['general']
@with_httmock(new_api_mock)