Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable form control change event emit from user (HTML) actions #26292

Closed
m-radzikowski opened this issue Oct 7, 2018 · 4 comments
Closed
Labels
area: forms feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature freq2: medium
Milestone

Comments

@m-radzikowski
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

When changing reactive form control value programmatically, we can disable emitting value change event by passing {emitEvent: false} as a second setValue() argument.
But when the form control is bound to HTML component in the template and user performs a change, there is no way I could found to prevent value change event from emitting.

Expected behavior

Allow enabling/disabling change event emitting as an option for form control. It should be possible when declaring form control (so probably in a AbstractControlOptions) and also as a AbstractControl method.
Form control with disabled event emitting should not emit change event after user changes in a view, and it's to discuss if it should by default also not emit events after programmatic changes by setValue() method.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/angular-gitter-jduydj
In a console you can see, that after choosing variant from the select change event is fired twice:

  • firstly with a new variant value, but old other controls values,
  • secondly with new other controls values, fired by updateValueAndValidity() call.

What is the motivation / use case for changing the behavior?

  1. Reduce number of fired events.
  2. In more complicated scenarios, firing event with incosistent data may lead to errors or wrong app behaviors, so it must be handled separately and introduces redundant logic to handle this special cases.

Only other option I can see to not fire that event is to not bind that control to template. But in this case we need to handle this control value separately, which also introduces redundant logic.

@manklu
Copy link

manklu commented Oct 7, 2018

You can use the following snippet to avoid the double emit in your case

import {debounceTime} from 'rxjs/operators'

...

this.form.valueChanges.pipe(debounceTime(0)).subscribe(data => {
  console.log('form value change', data);
});

@ngbot ngbot bot added this to the needsTriage milestone Oct 8, 2018
@kara kara added feature Issue that requests a new feature freq2: medium labels Oct 9, 2018
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Oct 9, 2018
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Jun 4, 2021
@angular-robot
Copy link
Contributor

angular-robot bot commented Jun 4, 2021

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@angular-robot
Copy link
Contributor

angular-robot bot commented Jun 25, 2021

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added the feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors label Jun 25, 2021
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: forms feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature: votes required Feature request which is currently still in the voting phase feature Issue that requests a new feature freq2: medium
Projects
None yet
Development

No branches or pull requests

5 participants