You can specify a delay to debounce the input event, a case scenario that you may want to wait for the user to stop typing then validate the field.
This can be achieved by adding a data-delay
attribute on the field being validated, and assign it the number of milliseconds you want to wait for.
After validating a file, you may want to reject the uploaded file if it fails the validation, this can be done by adding
the reject
modifier to directive. so you would use it like this: v-validate.reject
.
reject
modifier is only relevant on file inputs, adding it to other input types will not have an effect.
The basic approach relies on listening to the input
or the change
events depending on the file type.
However most of the time, your values are bound to your Vue instance and some code may change their inputs programatically, the basic approach won't detect this change.
The Solution: The v-validate
directive can take a binding expression, the expression is the data name you wish to validte. for example:
name
attribute, as the expression name will be used instead.
email
field was immediatly validated when you open the page, you may not want this behavior, use the initial
modifier to tell the validator to ignore the first evaluation like this: v-validate.initial
.
delay
attribute and reject
modifier won't have an effect anymore. so you might want to handle debouncing the inputs yourself.
You may want to trigger all inputs validation before submitting a form, maybe display an alert or prevent form submission if any errors are detected.
You may want to display error messages in different languages, here is an example on how you may do that. The language below is Arabic (RTL):
data-as
attribute which tells the validator to use that value as the field name when generating error messages, this is a good way to display 'pretty names' for your inputs in error messages, which would make sense when displaying messages in other languages.