How to use Radio Buttons in Kendo Form?

1 Answer 10 Views
Form RadioGroup
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Bob asked on 15 May 2025, 03:35 PM

I have a form where I want to use radio buttons to represent the item value, but I want the label of the radio buttons to be something different than the value.  For example, I have a name and I want to distinguish that name between a type of Person or Company, but the data value representing the name type is numeric.

I can setup the form like this:

<form id="myForm"></form>

<script>
    $("#myForm").kendoForm({
        formData: {
            ID: 1,
            Name: "John Doe",
            Type: 1  // 1 = Person, 2 = Company
        },
        items: [{
            field: "Name",
            validation: { required: true }
        }, {
            field: "Type",
            editor:"RadioGroup",
        editorOptions: {
          layout: "horizontal",
          items: [1, 2],
          select:function(e){              
            // Do something here?
          } 
        },
        }]
    });
</script>

Using Items: [1, 2] does work, but I don't want to show 1 and 2 on the radio buttons.  I want to show Person and Company.  How do I achieve that?  Can I set Items: ["Person", "Company"] and then do something in the select function?  If so, what needs to be done to set the model data correctly?

Please note that in my actual code, I am using setOptions for the model data, and not formData. 

Thanks, Bob

 

 

Bob
Top achievements
Rank 3
Iron
Iron
Veteran
commented on 16 May 2025, 03:46 AM

I have also found that the required message does not work with the RadioGroup.


            validation: {
                required: {
                    message: "The type field is required"
                },
            },
The behavior is no different than if the required: true is set.  The message shows the field name, not the custom message.

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 20 May 2025, 08:42 AM

Hello, Bob,

You can configure labels through the editorOptions field, similar to how the RadioGroup items are configured. Here you will find the modified version of your code snippet for reference.

As for the validation message, that is due to a known bug described in our Feedback Portal. You can follow the thread for further information on the matter.

Let me know if you have any further questions.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Bob
Top achievements
Rank 3
Iron
Iron
Veteran
commented on 20 May 2025, 02:51 PM

Thank you Martin, that is exactly what I was looking for.
Tags
Form RadioGroup
Asked by
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Martin
Telerik team
Share this question
or