...constschema:yup.SchemaOf=yup.object({group:yup.string().nullable().required (),description:yup.string().nullable().required(),user"> Validate fields of objects in form - Vue 3 + Vee-validate + yes-PHP Chinese Network Q&A
Validate fields of objects in form - Vue 3 + Vee-validate + yes
P粉486138196
P粉486138196 2023-11-16 13:56:09
0
1
597

I have a form where some fields are inside an object:

 

But the data validation of this object is only done after changing its external fields, i.e. filling ingroup,description,first_name,last_name(in the same order), and the form will not be considered valid only if you editgroupordescriptionagain.

How do I validate when I change a field myself?

Here is the link to the complete code.

I use the following version:

"vue":"^3.2.37", "vee-validate": "^4.5.11", "yup": "^0.32.11"


P粉486138196
P粉486138196

reply all (1)
P粉191610580

When you use useField() with an object, nested properties lose their reactive connections. So here are two options to solve this problem: wrap useField with reactive() or use separate useField() for each nested property.

Option 1

const { value: user } =reactive(useField('user'));

Option 2

const { value: first_name } = useField('user.first_name'); const { value: last_name } = useField('user.last_name');

Here is a working exampleHere

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!