The "value" property on radio buttons with FormControl doesn't get updated
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] 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 I query a radio input element, for example: myRadioInput
and check it’s value like myRadioInput.value
I get “on” instead of the actual value from “value”
Expected behavior
I expect that myRadioInput.value
will be the inputValue
or the formControl.value
I set on the component.
Minimal reproduction of the problem with instructions
In the following link:
- Open the console
- Click on the button
- See that instead of “good” it shows “on”
https://stackblitz.com/edit/angular-reactive-forms-radio-value-bug
What is the motivation / use case for changing the behavior?
For testing purposes, I need to be able to click on a certain radio input to manually select it. that’s why it’s important to be able to compare the radio.value to the manually selected value.
Environment
Angular version: 6.1.8
Browser:
- [x] Chrome (desktop) version 68.0.3440.106
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX
- Platform:
Others:
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
FormGroup updating FormControl value for radios ...
The Problem When adding radio-type inputs to FormGroup the value for the FormControl is updated immediately. In addition, changing the selected ...
Read more >Angular Reactive Forms: Tips and Tricks
When we want to get our FormGroup value we usually call the value property. For example: But there's one catch there. The value...
Read more >A thorough exploration of Angular Forms
This value accessor keeps track of the radio buttons with the help of an internal service: RadioControlRegistry , which holds an array of...
Read more >The "value" binding
When the user edits the value in the associated form control, it updates the value on your view model. Likewise, when you update...
Read more >Angular: Nested Reactive Forms Using ...
Lets take a look at the built-in value accessors provided by the Angular Core. Since our form control (component) doesn't falls in any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ericmartinezr Value is a property too.
When you have an input with the same name as HTML property, Angular ignores it and treat it as input only.
The radio value accessor has a
value
input, and therefore when you add theformControlName
, it ignores thevalue
property.You can see it easily in the following example:
Remove the directive and see what’s happening.
This behavior makes sense, but I agree that the value should also be reflected on the property
value
as it works with the text input element.