Skip to content

Add value change options to ControlValueAccessor writeValue and onChange #20230

@JSMike

Description

@JSMike

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[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

Current behavior

A component that implements ControlValueAccessor and transforms values to stay in bounds cannot respect { emitEvent: false } option when value patched, it will always emit an event if the onChange function is called.

Expected behavior

If a value is patched to a component that is out-of-bounds and cannot be displayed the component should be able to to transform the incoming value and also respect the option { emitEvent: false }.

updateControl should use an options object like patchValue/setValue.

Minimal reproduction of the problem with instructions

http://plnkr.co/edit/GyJLgvBkpPdD1y74lZOH?p=preview
In the reproduction you'll notice that when a value outside of the bounds is passed it will update the model. In doing so it will emit a change event to the console even if the new value was patched using { emitEvent: false }.

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

The default HTML5 slider will set the value of the slider to the max value if a value higher than the max is set. If I wanted to create a custom slider that followed the same behavior I couldn't do this without emitting an event even if patchValue(outofboundsvalue, { emitEvent: false }); is used.

Environment


Angular version: latest
I'm currently using 4.3.3, example plnkr uses latest.

Browser:
- [x] Chrome (desktop) version 61
This will be the same behavior in all browsers, but I've only tested with Chrome.

Others:
I'm not sure if this type of writeValue functionality is an anti-pattern or if a custom validator should be used instead. An HTML5 input fields will update a passed value to stay in bounds so I'm assuming Angular form components should have the option to do the same.

Also, not sure if this is a bug or intentional, so I labeled as feature request for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formsfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under considerationfreq2: medium

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions