Skip to content

bug(mat-bottom-sheet): custom form validation is executed multiple times #49959

Closed

Description

@ibrahimgabsi

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

13.3.9

Description

For one single change inside a form with custom validation, the validate() method is triggered multiple times.
The parameter is, first time, the form control where the change is applied, then the parent form group, and finaly the abstracted control.
This behavior occurs only within a form inside mat-bottom-sheet and starting from the version 14.x.x.

Reproduction

Steps to reproduce:

  1. (Please c.f. Stackblitz to reproduce the issue!! )
  2. Type something in the Phone number field and check that one log is outputed with the abstracted control
  3. Now, click Open bottom sheet and type something else. Note that multiple messages are outputed in the console for one single change

Expected Behavior

Expect validate() method to be executed one single time when a a single change is typed inside a mat-bottom-sheet.

Actual Behavior

validate() method is triggered multiple times.

Environment

  • Angular: 15.1.5
  • CDK/Material: <= 14.0.0
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Activity

  1. crisbeto commented on Apr 21, 2023

    @crisbeto
    Member

    The bottom sheet doesn't do anything special that would cause the validation to execute multiple times. It's just a dynamically-rendered component that has specific CSS. If there's an issue, it's likely in the forms module.

  2. added this to the needsTriage milestone on Apr 26, 2023
  3. added a commit that references this issue on May 12, 2023
    a4c8638
  4. garrettld commented on May 12, 2023

    @garrettld
    Contributor

    I've been looking into this, and it's unrelated to the bottom sheet and the forms module. What's happening is the NG_VALIDATORS token provided by the ChildComponent is being injected by all the form directives in spite of the fact that those directives use @Self.

    I've opened a PR to address this (#50270) that has more detail.

    edit: and here's a minimal reproduction: https://stackblitz.com/edit/angular-1fsxct?file=src/main.ts

  5. added a commit that references this issue on May 24, 2023
    98e8fdf
  6. angular-automatic-lock-bot commented on Jun 24, 2023

    @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.

  7. locked and limited conversation to collaborators on Jun 24, 2023
  8. added a commit that references this issue on Jan 23, 2024
    164e39e
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions