Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Radio button group pre selection does not work #341

Open

Description

@OliverHi

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

  • Version used: 6.1.1 (via npm)
  • Angular version used: 6
  • Browser Name and version: tested with chrome and firefox
  • Operating System and version (desktop or mobile): windows 10 desktop

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

Activity

  1. OliverHi commented on Aug 10, 2018

    @OliverHi
    Author

    PS updated stackblitz and text to describe the problem better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions