Problem/Motivation
Following #3549348: Fatal: Default value for props, on load
If the value of a required prop is removed from ContextualFormPanel, no control is done, the prop storage is updated and we have a fatal error (probably Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template The property xxx is required.)
In UI Patterns 2, we rely on Form API blocking ComponentForm submission to avoid this unfortunate situation.
Proposed resolution
Must be done in 2 steps:
- Client side: Don't send the request to
display_builder.api_updatemaybe by adding hx-validate https://htmx.org/attributes/hx-validate/ toonInstanceFormChangeandonInstanceUpdateButtonClickHTMX events. - Server-side:: in
ApiController::update(), don't update the instance (InstanceInterface->setSource()) if the form is not validating
Issue fork display_builder-3549761
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pdureau commentedFor information, the related issue on SDC Devel: #3551361: Raise an error when a required prop has no default value
Comment #3
just_like_good_vibesComment #5
pdureau commentedNeeds work. Don't use
FormAjaxExceptionbutApiController::responseMessageError()because we already handle this kind of situations.Comment #6
just_like_good_vibesComment #7
pdureau commentedFunctional review: OK for me.
What about the technical implementation? Is it OK too?
Comment #9
mogtofu33 commentedI am not sure about the try/catch instead of responseMessageError, as we are hiding the error in the request.
Comment #10
mogtofu33 commentedComment #11
pdureau commentedComment #12
just_like_good_vibesi did some little changes and added some comments :)
Comment #13
mogtofu33 commented