question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposition : $errors as array of non passing validators

See original GitHub issue

Hi !

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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
thedamoncommented, Apr 26, 2019

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.

1reaction
dobromir-hristovcommented, Sep 23, 2019

I get what you mean. I have plans to extract those helpers, just been super busy lately.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found