Home vue.js vuelidate, how to make a custom check?

vuelidate, how to make a custom check?

Author

Date

Category

I need to make a check using Vuelidate, does the line be starting with the figure 7? In the docks found something like that:

phone: {
Required
MINLENGTH: MINLENGTH (11),
MaxLength: MaxLength (11),
ISPhone (Phone) {
If (Phone [0] === '7') {
  RETURN TRUE;
}
},

},

But when using V-if = "! $ v.form.phone.isphone" Error crashes: Error in Render: "TypeRerror: Cannot Read Property '__ISVuelidateAsyncvm' of undefined" . Who will do how to do it. And also, if you know how to check whether there is any errors in validation (in all form), how can this be verified to do what the disabled buttons do?


Answer 1, Authority 100%

In the docks there is an example of https://vuelidate.js.org/#custom-Validators

There is still a good example here https: // vuejsdevelopers .com / 2018/08/27 / VUE-JS-Form-Handling-Vuelidate /

You should create a separate Validators.js file, where custom validation functions will be placed, file content example:

Export Function Isphone (Phone) {
  Return Phone [0] === '7'
}

Then this file is connected in the component:

import {iSPhone} from "./validators";

And then it is already used to use this custom validator as well as built-in.

And even if you know how to check whether there is any errors in validation (in all form), then how can this be verified to do what to make disabled buttons?

You can use such an inspection, in more detail in the docks in the Data Nesting section:

this. $ v. $ invalid

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions