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.

return promise after all fields are validated

See original GitHub issue

Hello,

I try to realise a form which prevents submitting if validation fails. I have several rules returning promises.

How do I know if validation is completed for all fields using the validateAll method without validating all fields manually? I have not found any events or callbacks helping me to achieve this behaviour.

Regards, Andreas

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
logaretmcommented, Nov 23, 2016

@hootlex yep, now the plugin does not rely on the events to trigger the validations, also validateAll will now always return a Promise regardless of what rules were used in the validation, which should make it more predictable/consistent. the same if you are passing values to it it will return also a promise.

however it currently does not throw or trigger rejections, which if implemented later will make it more natural to use and very clear, I want to be used like this:

this.$validator.validateAll().then(() => {
   // do success things.
}).catch(() => {
  // something failed the validation.
});
1reaction
hootlexcommented, Nov 23, 2016

@logaretm great job man! 👌 I have to refactor my projects to take advantage of this asap.

Read more comments on GitHub >

github_iconTop Results From Across the Web

validate data and then return resolve? - Stack Overflow
If all fields validaton require async operation, you can use Promise.all, which will be resolved only if all the fields validation have been ......
Read more >
Promise-Based Validation - Code - Envato Tuts+
Only the operation truly knows when it has completed; as such, it is responsibile for notifying its result using the Promises/A+ contract. In ......
Read more >
Using promises - JavaScript - MDN Web Docs
Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function. Imagine a function, ...
Read more >
promise validator - FormValidation
The promise option must be a function or the name of function which returns a Promise as following: promise: function(input) {. // input.value...
Read more >
JavaScript Promises: race, all, allSettled, and then
With promise methods like Promise.all() — which takes an array of promises as an argument a returns a promise that resolves when all...
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