Description
Is your feature request related to an issue? Please describe.
Initial issue:
Block validations are not working properly inside inline blocks, such as Grid, Column, and others.
For simulate:
It is possible to simulate with any block that has validation within the Grid. I recommend using the Teaser block that comes natively, as it requires an href.
Root cause:
Validation in the onSubmit
method inside the Form is only applied to blocks at the root of the structure, meaning that inner blocks inside inline components are not validated.
volto/packages/volto/src/components/manage/Form/Form.jsx
Lines 517 to 566 in 91b2258
Another test I performed was the validation within the Column block from the @eeacms/volto-columns-block community.
Passing errors from props in Container Edit:
Another issue is that error properties inside ContainerEdit are not being passed to BlockForm.
Solution suggestion
A potential solution would be to create a recursive helper function, such as blockValidator
, that checks for the presence of the blocks
and blocks_layout
fields in a block. This function should be able to validate inner blocks up to a depth of level 1, ensuring that inner errors are detected and handled better.
Problems that may arise that could be addressed with this solution:
Error differentiation:
It is important to differentiate internal errors from regular block errors. One possible approach could be to give internal errors a specific key, such as @internal_blocks
. This would allow for proper handling, especially when setting up the error toast and moving focus to the correct element.
volto/packages/volto/src/components/manage/Form/Form.jsx
Lines 601 to 624 in 91b2258
Visibility of errors in internal block forms:
Another problem arises when internal block forms fail to detect the associated errors due to the dependency on element IDs in the root blocksErrors
object. A fix could be to add internal block errors to the root structure, (this would be duplicated both at the root and within the parent block with the @internal_blocks
key) ensuring that they are identified and displayed correctly. (This workaround may not be ideal, but it avoids major changes and significant impacts to the rest of the system.)