Proposition : $errors as array of non passing validators
See original GitHub issueHi !
I’d like to know if it would be possible to add an array of validator’s names ($errors
) for each non passing validator of each value :
How would it look like :
// here nothing change
validations: {
foo: { required, minLength: minLength(4) }
}
// ... somewhere later (or by user input)
foo = ''
console.log($v.foo.$errors) // ['required, 'minLength']
foo = 'foo'
console.log($v.foo.$errors) // ['minLength']
foo = 'foobar'
console.log($v.foo.$errors) // []
This would enable :
- validator priority (defined by key order)
- possibility to list all the errors in template :
<strong v-for="error in $v.foo.$errors">{{ error }}</strong>
- possibility to use validator key as reference for i18n :
<strong v-if="$v.foo.$errors.length">{{ $t($v.foo.$errors[0]) }}</strong>
How hard would that be :
Probably not much more than a new validation getter such as :
$errors() {
const proxy = this.proxy
return this.ruleKeys.filter((rule) => !proxy[rule])
},
If this feature is not already coded, and you’re willing to accept it but have no time to code it, let me know and i’ll submit a PR.
Thanks for reading !
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Proper way to validate array inside angularjs form?
Validate the form on server when submit and pass back errors to client. Now i attach service prop 'error', but it seems not...
Read more >Using VueTypes Validators - GitHub Pages
Validates that a prop is an array of a certain type. Accepts JavaScript constructors, Vue.js props validation objects and VueTypes validators ...
Read more >Validation | Vue Formulate ⚡️ The easiest way to build forms ...
Validation errors are always computed in realtime, but they are displayed based on error-behavior of the input. The default error-behavior is blur —...
Read more >Validation - JSON Forms
Validate input data and display errors accordingly. ... can be customized by passing a custom AJV instance as a prop to the JsonForms...
Read more >Validation - react-jsonschema-form documentation
Validation error messages are provided by the JSON Schema validation by default. If you need to change these messages or make any other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The vuelidate-error-extractor doesn’t seem to do what this suggests. It seems to be entirely oriented around templating. I already have my templating pattern figured out and would just like an array of error fields in the style of vuelidate (ie data only) for a11y purposes.
I get what you mean. I have plans to extract those helpers, just been super busy lately.