Placeholder support in async validations
See original GitHub issueIt would be nice to have placeholder support for the attribute name inside the error message returned for the callback in an async validation. This is posible with synchronous validations right now.
Actual behavior
Validator.registerAsync(
'unique',
(value, args, attribute, passes) => {
// database check
passes(false, 'The :attribute has already been taken.'); // It doesn't work!
}
);
Expected behavior
Validator.registerAsync(
'unique',
(value, args, attribute, passes) => {
// database check
passes(false, 'The :attribute has already been taken.'); // The username has already been taken.
}
);
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top Results From Across the Web
Placeholder support in async validations · Issue #301 - GitHub
I want to apply an unique rule which query from DB, and generate dynamically error message. I don't understand what passes is?
Read more >Using Custom Async Validators in Angular Reactive Forms
We are going to create a very minimalist form that does one thing: check if the username already exists. In this case, we...
Read more >Async Change Validation Example - Redux Form
To provide asynchronous validation, provide redux-form with an asynchronous validation function ( asyncValidate ) that takes an object of form values, and the ......
Read more >Async validator for unique userId not working - Stack Overflow
When I start entering anything the input field, it shows "Cannot read property 'existingUserId' of null". I've already followed various ...
Read more >How to Add Async Validators to an Angular Reactive Form
Learn how you can add async validators to your reactive form in Angular.
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 FreeTop 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
Top GitHub Comments
@haitm-eas I wrote an example showing how to register an async rule in #302.
You can generate the error message dynamically before passing it to
passes
function.You need to pass a callback to
passes
function if the validator has one or more async rules. Related with “Use the same API for sync and async validations” in #303@haitm-eas The example is showing how to make an async rule using promises, not
async/await
. The callback is a normal function, not an async function.