primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Radiobutton onClick is emitted before the form value is changed

Open davisb10 opened this issue 8 years ago • 3 comments

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

[X] bug report
[ ] feature request
[ ] support request

Plunkr Case (Bug Reports) Please demonstrate your case at stackblitz by using the issue template below. Issues without a test case have much less possibility to be reviewd in detail and assisted.

https://stackblitz.com/edit/github-hbohrm

Current behavior

When using the radio button with ReactiveForms and the onClick() method, the event is fired before the form value is changed.

Expected behavior

The event should be called after the form value is updated.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/github-hbohrm.

View the console log. Click on any value. The default is shown on first click.

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

Motivation is that I need to be able to have actions performed based off the selected radio button value.

Please tell us about your environment:

  • Angular version: 7.0.1
  • PrimeNG version: Any

davisb10 avatar Oct 29 '18 16:10 davisb10

There is [(ngModel)] and you can subscribe to (ngModelChange)="selectionChanged($event)" event. Click always goes before model changes.

TiGGeRTSK avatar Nov 02 '18 08:11 TiGGeRTSK

That doesn't work when my form is a reactive form. That would work if I was using [(ngModel)].

This should honestly work similarly to how Angular Material does its change() event. Angular Material Radio

davisb10 avatar Nov 02 '18 11:11 davisb10

I had a reactive form and worked around this issue by subscribing to the form value changed in my controller after setting up the form

this.form.get('radioButton').valueChanges.subscribe(v => { console.log(v); // Call what ever function I want to call on change of value });

Hovemeyer5 avatar Sep 09 '19 14:09 Hovemeyer5