question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The "value" property on radio buttons with FormControl doesn't get updated

See original GitHub issue

I’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:

  1. Open the console
  2. Click on the button
  3. 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:open
  • Created 5 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
lazarljubenoviccommented, Sep 20, 2018

@ericmartinezr Value is a property too.

image

3reactions
NetanelBasalcommented, Oct 2, 2018

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 the formControlName, it ignores the value property.

You can see it easily in the following example:

@Directive({
  selector: '[srcIgnored]'
})
export class MyDirective { 
  @Input() src;
}
<img srcIgnored [src]="'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Angular_full_color_logo.svg/1200px-Angular_full_color_logo.svg.png'">

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found