How do I set the checked state of a radio button for a number value?

1 Answer 47 Views
RadioButton
Tom
Top achievements
Rank 2
Tom asked on 26 Feb 2025, 03:53 PM

Hello!  I am having difficulty with the following scenario:  I have an array of objects that I'm displaying in my UI in the form of a table.  On my table I have the following columns: Name (string), PreferenceLevel (number), IsActive (bool).  I am using an *ngFor="let item of items" to render all of the table data.  The name looks great, as does the isActive,. For IsActive I am using a kendo-checkbox like this:

<kendo-checkbox [checkedState]="item.isActive" [(ngModel)]="item.isActive"></kendo-checkbox>

and it seems to render as checked or unchecked well based on the boolean that is coming across.

My Preference Level column is another story.  I have 4 preference levels based on 4 integers: 0,1,2,3.  I would like to have a radio button as the UI for this column, but cannot seem to get them to represent the data that is coming through.  Here's what I have:

<span style="padding-left:5px;">
  <kendo-radiobutton #radio0 value=0  [(ngModel)]="item.preferenceLevel"></kendo-radiobutton>
  <kendo-label class="k-radio-label" [for]="radio0" text="None"></kendo-label>
  <kendo-radiobutton #radio1 value=1  [(ngModel)]="item.preferenceLevel"></kendo-radiobutton>
  <kendo-label class="k-radio-label" [for]="radio1" text="+1"></kendo-label>
  <kendo-radiobutton #radio2 value=2  [(ngModel)]="item.preferenceLevel"></kendo-radiobutton>
  <kendo-label class="k-radio-label" [for]="radio2" text="+2"></kendo-label>
  <kendo-radiobutton #radio3 value=3  [(ngModel)]="item.preferenceLevel"></kendo-radiobutton>
  <kendo-label class="k-radio-label" [for]="radio3" text="+3"></kendo-label>
</span>

Perhaps I need to assign a checkedState or checked attribute in there like I did for the check box, but I can't figure out how to do it for the radio button.  Or perhaps the radio buttons can only process string values? (I saw only string examples in your documentation) There is nothing checked in my table with my markup as is above, though.  Please advise.

1 Answer, 1 is accepted

Sort by
0
Yanmario
Telerik team
answered on 03 Mar 2025, 10:02 AM

Hi Thomas,

The radio button value property currently only accepts string values. Therefore, the developer must provide a string value for it to work correctly. In your case, you can cast the value to a string similar to the following example:

https://stackblitz.com/edit/angular-b9edeg9u?file=src%2Fapp%2Fapp.component.ts

I hope this is what you are looking for as a solution.

Regards,
Yanmario
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Tags
RadioButton
Asked by
Tom
Top achievements
Rank 2
Answers by
Yanmario
Telerik team
Share this question
or