How to apply validation on nested components #4326
Replies: 1 comment 1 reply
-
This would be an advanced use case, I probably should add an example for that in the docs. So you should try to think of the Then you will use I may add an example later, but this is minor guidance that can help you. Let me know if face further issues till I get around to adding that example. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have a question regarding validation with nested components.
I mean by "nested components" :
I have a component called PhoneBox in which I have two custom components
<PhoneBox v-model="mobile" label="Phone" name="xxx"></PhoneBox>
PhoneBox component :
The textbox component is a wrapper from input used with UseField with its own ErrorMessage. Everything is working correctly when playing with validations, they can show their own ErrorMessages (that can be hidden with the hide-error properties).
I would like to find a way to create a validation rule, that I can pass in the PhoneBox component, that will be applied to the 2 textbox.
For now, I have 1 solution that get me close to a solution, but I am stuck...
I created a schema like:
that I send in the PhoneBox component:
<PhoneBox v-model="mobile" label="Phone" name="rules"></PhoneBox>
In the component I applied the rules like this.
with declaring the UseFiled like :
const { value, meta, errors } = useField<string | null>(props.name as string)
it triggers correctly the errors of the 2 textBox
As you can see, the errors are triggered at the TextBox level, but I would like that it triggers the error at the PhoneBox component level.
I have the feeling that I need to complete the schema with somthing like this:
But I don't find anything in the documentation :/
Did you already had this kind of situation ?
Thank for the answers !
Beta Was this translation helpful? Give feedback.
All reactions