templates: allow displaying dynamic error message on forms created via Form Builder plugin #11275
+21
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Close #11274
Why this PR?
I've created a custom phone number input block for my form builder, including validation. However, the component on the frontend only displays the generic message "This field is required," even when formState.errors contains specific error messages. This is not the expected behavior. I need the component to display the error messages from formState.errors.
Description
This pull request includes changes to improve error handling in various form components by passing the
name
prop to theError
component and updating theError
component to display specific error messages.Error handling improvements:
templates/website/src/blocks/Form/Error/index.tsx
: Updated theError
component to accept aname
prop and useuseFormContext
to display specific error messages.Form component updates:
templates/website/src/blocks/Form/Checkbox/index.tsx
: Modified to pass thename
prop to theError
component.templates/website/src/blocks/Form/Country/index.tsx
: Modified to pass thename
prop to theError
component.templates/website/src/blocks/Form/Email/index.tsx
: Modified to pass thename
prop to theError
component.templates/website/src/blocks/Form/Number/index.tsx
: Modified to pass thename
prop to theError
component.templates/website/src/blocks/Form/Select/index.tsx
: Modified to pass thename
prop to theError
component.templates/website/src/blocks/Form/State/index.tsx
: Modified to pass thename
prop to theError
component.templates/website/src/blocks/Form/Text/index.tsx
: Modified to pass thename
prop to theError
component.templates/website/src/blocks/Form/Textarea/index.tsx
: Modified to pass thename
prop to theError
component.