Skip to content

FormBuilder.group() calls each custom-validator 3 times #14551

Closed

Description

@MickL

I'm submitting a ...

[X] bug report
[ ] feature request
[ ] support request

Current behavior
FormBuilder.group() calls each custom-validator 3 times per FormControl. Same behavior on sync- and async-validators.

Calling "this.form.controls.KEY.updateValueAndValidity();" would call another validation.

Expected behavior
custom-validators should be called only once.

Minimal reproduction of the problem with instructions
Plunker:
https://plnkr.co/edit/ejTYTlQc9hxXnPSD2qRa?p=preview
(Please see console)

Angular version:
2.4.1

Activity

  1. changed the title [-]FormBuilder.group() calls each custom-validator 4 times[/-] [+]FormBuilder.group() calls each custom-validator 3 times[/+] on Feb 17, 2017
  2. kelvinsleonardo commented on Oct 31, 2017

    @kelvinsleonardo

    I have same problem, is there any solution of it ?

  3. mhevery commented on Dec 19, 2017

    @mhevery
    Contributor

    There is no guarantees how many times the validator gets called. Your code should be idempotent to the number of calls.

  4. MickL commented on Dec 19, 2017

    @MickL
    Author

    Custom validators are often used for http validation. Why do 3 http requests if one is enough and nothing changed? Please reopen as a feature request then.

  5. MickL commented on Mar 14, 2018

    @MickL
    Author

    @mhevery Please reopen! Imagine having 1 million users and 3 million requests instead of 1 million. Thats an unnecessary workload of 300%.

  6. seritools commented on Apr 20, 2018

    @seritools

    @MickL Try using a small delay in your pipe before doing your http request. This causes the async validators to be cancelled before the request happens, as the validation engine cancels the ongoing validations.

  7. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions