Rule is called twice, calling backend service, so undesirable
See original GitHub issueHi,
Please see code of my constructor below. What I (obviously) want to achieve is that a backend service is only called when the email address is “valid”. This works. When the email address is valid though, I see that the backend service is called twice. Am I doing something wrong? Or is this a bug?
BTW, As you can see I implemented my own regex(this._emailRegex) to test for valid email address. Can I also call the standard validation rule? Why do I need to test this again as I also have the email() already in the chain.
Thanks!
Sander
constructor(private userService: UserService, private controllerFactory: ValidationControllerFactory) {
this.controller = controllerFactory.createForCurrentScope();
this.controller.validateTrigger = validateTrigger.change;
validationMessages['passwordmatch'] = `Passwords don't match`;
validationMessages['alreadyexists'] = `Email already exists!`;
ValidationRules.customRule('passwordmatch',
(value, obj) => {
return obj.password === obj.password2;
}, validationMessages['passwordmatch']);
ValidationRules.customRule('alreadyexists',
(value, obj) => {
if (this._emailRegex.test(obj.email)) {
return this.userService.exists(obj.email);
} else {
return true;
}
}, validationMessages['alreadyexists']);
ValidationRules
.ensure('fullname')
.required()
.ensure('email')
.required()
.email()
.satisfiesRule('alreadyexists')
.ensure('password')
.required()
.ensure('password2')
.required()
.satisfiesRule('passwordmatch')
.on(this._user);
setTimeout(() => this.controller.validate(), 500);
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Why is my fetch getting called twice? : r/reactjs - Reddit
It shows it getting called twice in the console, but only shows once rendered on the page.
Read more >Why is ngOnInit called twice? - angular - Stack Overflow
Right now, if an error happens during detecting changes of content/view children of a component, ngOnInit will be called twice (seen in DynamicChangeDetector)....
Read more >The three most important AWS WAF rate-based rules
A URI-specific rule can prevent a single source IP address from connecting to the login page as few as 100 times per 5-minute...
Read more >502 Bad Gateway Unexpected EOF | Apigee Edge
The HTTP status code 502 means that the client is not receiving a valid response from the backend servers that should actually fulfill...
Read more >Rule syntax | Semgrep
This document describes Semgrep's YAML rule syntax including required and optional fields. Just getting started with Semgrep rule writing?
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
You can use the
Validator
to evaluate rules without causing side-effects in the UI. The.tag(name)
fluent API feature along withValidationRules.taggedRules
enables referencing and evaluating specific rules in the set.Does this answer the question?
Sorry for misusing this closed issue thread to ask questions. Now I have this error:
thrown by:
I tried THIS (This one doesn’t throw the exception, but it just doesn’t work):
THIS, because I found this this issue (Exception)
THIS (Exception)
AND THIS (Exception)
None of these work. Bug? Or am I doing something wrong? (again 😉
Sander
BTW (see below), THAT also doesn’t work(no exceptions, but the console.log(‘Im here!!’, obj)) is never called 😉