Skip to content

Commit

Permalink
🐛 [#4241] Fix validation of field with nested key in fieldset
Browse files Browse the repository at this point in the history
by not adding a serializer field for layout components
  • Loading branch information
stevenbal committed May 24, 2024
1 parent 1e0c46b commit 3575b29
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/openforms/formio/rendering/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
9 changes: 8 additions & 1 deletion src/openforms/formio/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/openforms/formio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ 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
if component["type"] == "editgrid":
return False

column = component.get("columns")
components = component.get("components")
rows = component.get("rows")
Expand Down
2 changes: 1 addition & 1 deletion src/openforms/forms/models/form_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3575b29

Please sign in to comment.