From 83dd7771f5a15f4cecc38a5c457e2bdf87ad27f7 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Fri, 24 May 2024 15:08:45 +0200 Subject: [PATCH] :bug: [#4241] Fix validation of field with nested key in fieldset by not adding a serializer field for layout components --- src/openforms/formio/rendering/nodes.py | 5 ++++- src/openforms/formio/serializers.py | 9 ++++++++- src/openforms/formio/utils.py | 4 ++++ src/openforms/forms/models/form_variable.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/openforms/formio/rendering/nodes.py b/src/openforms/formio/rendering/nodes.py index b96fb8ab70..3f40e41246 100644 --- a/src/openforms/formio/rendering/nodes.py +++ b/src/openforms/formio/rendering/nodes.py @@ -230,7 +230,10 @@ def __iter__(self) -> Iterator["ComponentNode"]: return # in export mode, only emit if the component is not a layout component - if self.mode != RenderModes.export or not is_layout_component(self.component): + if self.mode != RenderModes.export or ( + not is_layout_component(self.component) + and self.component["type"] != "editgrid" + ): yield self for child in self.get_children(): diff --git a/src/openforms/formio/serializers.py b/src/openforms/formio/serializers.py index 2569fae068..a291be9aa8 100644 --- a/src/openforms/formio/serializers.py +++ b/src/openforms/formio/serializers.py @@ -18,7 +18,7 @@ from .datastructures import FormioConfigurationWrapper from .typing import Component -from .utils import iter_components +from .utils import is_layout_component, iter_components if TYPE_CHECKING: from .registry import ComponentRegistry @@ -62,6 +62,10 @@ def apply_hidden_state( if is_visible: continue + # Layout components do not have serializer fields associated with them + if is_layout_component(component): + continue + # when it's not visible, grab the field from the serializer and remove all # the validators to match Formio's behaviour. serializer_field = glom(fields, component["key"]) @@ -149,6 +153,9 @@ def build_serializer( config: JSONObject = {"components": components} for component in iter_components(config, recurse_into_editgrid=False): + if is_layout_component(component): + continue + field = register.build_serializer_field(component) assign(obj=fields, path=component["key"], val=field, missing=dict) diff --git a/src/openforms/formio/utils.py b/src/openforms/formio/utils.py index b444480e35..fb7e18ebcd 100644 --- a/src/openforms/formio/utils.py +++ b/src/openforms/formio/utils.py @@ -159,6 +159,10 @@ def get_readable_path_from_configuration_path( def is_layout_component(component: Component) -> bool: # Adapted from isLayoutComponent util function in Formio # https://github.com/formio/formio.js/blob/4.13.x/src/utils/formUtils.js#L25 + # FIXME ideally there would be a cleaner fix for this + if component["type"] == "editgrid": + return False + column = component.get("columns") components = component.get("components") rows = component.get("rows") diff --git a/src/openforms/forms/models/form_variable.py b/src/openforms/forms/models/form_variable.py index a642080b65..1aa0493cd8 100644 --- a/src/openforms/forms/models/form_variable.py +++ b/src/openforms/forms/models/form_variable.py @@ -53,7 +53,7 @@ def create_for_formstep(self, form_step: "FormStep") -> list["FormVariable"]: configuration=form_definition_configuration, recursive=True ): if ( - (is_layout_component(component) and not component["type"] == "editgrid") + is_layout_component(component) or component["type"] == "content" or component["key"] in existing_form_variables_keys or component_in_editgrid(form_definition_configuration, component)