Skip to content

Unified Control State Change Events (FormControl should also support pristine/touched/untouched/valid events) #10887

@btrauma8

Description

@btrauma8

Original report is below -- we have merged #42862 into this bug while organizing our issue tracker.

Which @angular/* package(s) are relevant/releated to the feature request?

forms

Description

The ability for AbstractControl-based classes (such as FormControl) to produce more events is a highly requested feature (lots of feedback in #10887, also #41088 and others; #24444 is also a use case). Adding more observables similar to the current valueChanges and statusChanges is the most straightforward way to extend AbstractControl, however, as the number of such observables increases (for example pristine, dirty, etc) it might become less ergonomic and more expensive to maintain. Additionally, if we wish to support the same state changes in ControlValueAccessor, we would be duplicating a lot of individual cases.

Proposed solution

We could introduce a new observable (and still support valueChanges and statusChanges for backwards compatibility) containing all events produced in various situations, so it's possible to subscribe, stream, and filter as needed. Each event in this stream might contain additional meta information such as a reference to an instance that produced the event, event type, etc. We would need a unified payload design that works with all the event types, and satisfies the use cases in the above linked issues.

However before making a final decision, we'd need to perform more research and design work, to make sure that this approach is viable.

Also note that adding this stream could simplify ControlValueAccessor, as per #24444 and #27315.

Alternatives considered

Adding individual observables on a case-by-case basis is likely infeasible, both from an API consistency perspective and an API bloat perspective.


I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
FormControl doesn't have an observable to subscribe to for when one of the following has changed:
pristine/touched/untouched/valid (well, okay, it does for valid, but i want to include the others)
statusChanges just tells me VALID or INVALID and only fires when valid changes.
i need to know when touched changed

Expected/desired behavior
either an observable for every one or one that combines them all...
fc.touchedChanges.subscribe(x => ....stuff);

What is the motivation / use case for changing the behavior?
The reason i want this is that i am making little form components and sending FormControl as input to one of them. I don't want a lot of logic in the component's html.
i would like to avoid <span *ngIf="myControl.valid && myControl.pristine || !myCointrol.blah ...
instead, i want: <span *ngIf="showWarning">
and showWarning could be set from a subscription in the component looking at pristine/touched etc

  • Angular version: 2.0.0-rc.5

Metadata

Metadata

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: formscanonicalThis issue represents a canonical design issue in Angular.design complexity: majorfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under considerationforms: ControlValueAccessorforms: Controls APIIssues related to AbstractControl, FormControl, FormGroup, FormArray.state: Needs Design

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions