sherweb / ngx-materialize

Angular wrap around Materialize library
https://sherweb.github.io/ngx-materialize/
Apache License 2.0
314 stars 75 forks source link

Radio button group pre selection does not work #341

Open OliverHi opened 6 years ago

OliverHi commented 6 years ago

Expected Behavior

A radio button group that has ngModel connected to it should be able to (pre)select the right radio button that corresponds to the model. Even if the selected part of the model is an object

Current Behavior

Currently no selection is made. I had similar issues with selects that seem to happen because of the linked model beeing (complex) objects. Implementing a custom [compareWith]=... helped there (by simply comparing ids). Otherwise only object reference seems to be compared. Radio buttons do not seem to have a similar attribute so this did not work here.

Possible Solution

Maybe add a custom way to compare for radio buttons?

Steps to Reproduce (for bugs)

  1. Create radiobuttons with *ngFor based on an array of objects
  2. Fill the "target" model, the one linked to the radio button via ngModel, with an exact copy of an object from the array (but not the same object, just a copy)
  3. None of the radio buttons gets selected

Here is a stackblitz demonstrating the problem.

Context

I am trying to display a form for a user to change existing data. Some of that should be displayed as a radio group where the selection from last time gets preselected on reopening. The possible values for the radio buttons and the users selection get loaded seperately from a server. That is why they contain the same object (content wise) but have different object references, which seems to confuse ngx-materialize's radiobuttons. Ignoring this problem I loved the library until now, so a fix or workaround for this would be great!

Your Environment

If more information is needed I will try to provide that.

OliverHi commented 6 years ago

PS updated stackblitz and text to describe the problem better