-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to validate nested components in EditForm #60127
Comments
Hi @Bond-Addict your repo doesn't appear to exist. Did you set it to private? |
Yup, my bad. It's public now |
@Bond-Addict nested properties should be validated in your case. The issue was that you didn't set a rendermode <HeadOutlet />
...
<Routes /> To <HeadOutlet @rendermode="InteractiveServer" />
...
<Routes @rendermode=InteractiveServer /> Your application will work. You can read more about Rendermodes here You can simplify your code by getting rid of everything in the [Parameter]
public Address Address { get; set; } |
I'll check that out shortly. Thank you! |
So even after that change, the address component isn't validated. I updated the repo just in case I misunderstood the instructions. |
@Bond-Addict I spotted my error, I missed the fact that the address wasn't validated when pressing the submit button, (after the above change it was correctly validating the individual fields while editing, but not when pressing the submit button). When pressing submit the By adding the following code inside the PersonValidator RuleFor(p => p.Address).SetValidator(new AddressValidator()); The address will now also be validated when pressing submit. |
This is POC repo which demonstrates the issue and what I've tried so far
https://github.com/[Bond-Addict/NestedValidation](https://github.com/Bond-Addict/NestedValidation)
I've tried several different validation libraries with no luck. This would seem to be a common use-case but I've been able to find a solution.
Issue:
When using a EditForm in a parent component, child components do not emit their validation state up to parent.
Current Attempt
Registering the EditContext as a
CascadingParameter
on the child. When validation is requested from the parent try and update the EditContext message store to include the invalid fields from the child.Info:
The validators both work and validate as expected and the child component does correctly get notified when validation is requested on the EditContext.
The text was updated successfully, but these errors were encountered: