From ce0a65a35ece81c714c3259adfb8445945675504 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 12 May 2022 17:24:05 +0200 Subject: [PATCH] manager: avoid validation errors on dynamic fields in cell edit form (#65163) --- combo/manager/views.py | 6 ++++-- tests/test_dataviz.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/combo/manager/views.py b/combo/manager/views.py index 041da791..4450c234 100644 --- a/combo/manager/views.py +++ b/combo/manager/views.py @@ -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: diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index c96f42da..435092ce 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -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)