How Best to Use Radio Buttons With Controllers

This forum allows users to post and respond to "How Do I Do ....." questions. The information contained in this forum has not been validated by K-Rise Systems and, as such, K-Rise Systems cannot guarantee the accuracy of the information.
Post Reply
JefferyD
Posts: 178
Joined: August 31st, 2021, 11:37 am
Contact:

How Best to Use Radio Buttons With Controllers

Unread post by JefferyD »

I have some individual radio buttons to select different sections, and one of the sections has a list of radio buttons. I'm at the point where I need to pass the selected options into a controller and I'm struggling to figure out how to get a value based on what is selected. Is there an easy way to assign a value to a radio button and retrieve that value from the radio button selected with a specific group name?
Radio Buttons Example.png
Radio Buttons Example.png (18.38 KiB) Viewed 2284 times
Radio Buttons Example.png
Radio Buttons Example.png (18.38 KiB) Viewed 2284 times
Last edited by JefferyD on March 18th, 2022, 4:58 pm, edited 1 time in total. word count: 101

Tags:
steve.sakhnini
Posts: 40
Joined: February 9th, 2022, 12:03 pm
Contact:

Re: How Best to Use Radio Buttons With Controllers

Unread post by steve.sakhnini »

In JavaScript there is no direct way to get the selected radio button from a group so you would need to run some JS to find the selected one
ex:

Code: Select all

document.querySelector("input[name='some_shared_name']:checked").value
or with JQuery:

Code: Select all

$("input[name='some_shared_name']:checked").val();

Alternatively you can have a hidden input with each set of buttons that will be updated when one of the buttons fires a change event, then you grab the value of the input when you need to find out the selected button, this approach might be easier in EP since it requires no additional js code.
word count: 110
JefferyD
Posts: 178
Joined: August 31st, 2021, 11:37 am
Contact:

Re: How Best to Use Radio Buttons With Controllers

Unread post by JefferyD »

I can get the selected one pretty easily, but it started to get really complicated when I realized that the only value I could get from it is the associated text that is displayed next to it. I somewhat like your idea of updating a hidden input using a change event and then reading the value from there. Seems a little complicated for something I feel should have a more direct option.

To break it down a bit
  • No value seems to be configurable besides the displayed text for radio buttons
  • The displayed text is an issue because:
    • The displayed text won't necessarily match the desired value
    • Sometimes it may even be desirable to have a value with no displayed text at all
  • Assigning a value any other way makes it very difficult to actually retrieve from the context of the checked radio button
  • Going with the approach of setting the value of a hidden input adds complexity and makes future changes more difficult
Suggestion
It would be nice to be able to assign a hidden value directly to a radio button and then just use the group name in the controller to pull that value directly. Almost simulating pulling a value from a dropdown list.
word count: 207
kathy.pride
Posts: 47
Joined: September 7th, 2021, 1:04 pm
Contact:

Re: How Best to Use Radio Buttons With Controllers

Unread post by kathy.pride »

It would be nice if radio buttons worked the same in MVC as they do in Classic. Simple to assign values and being able to assign a default text of blank.
Attachments
Classic Radio Button.png
Classic Radio Button Default Text.png
Classic Radio Button Default Text.png (5.06 KiB) Viewed 2261 times
Classic Radio Button Default Text.png
Classic Radio Button Default Text.png (5.06 KiB) Viewed 2261 times
word count: 31
steve.sakhnini
Posts: 40
Joined: February 9th, 2022, 12:03 pm
Contact:

Re: How Best to Use Radio Buttons With Controllers

Unread post by steve.sakhnini »

The radio button control is missing a value property.
kathy, this should allow you to leave the text property empty for no label.

Task #10263 has been created for this issue, this post will be updated once it is resolved.
Last edited by steve.sakhnini on March 21st, 2022, 10:46 am, edited 2 times in total. word count: 40
steve.sakhnini
Posts: 40
Joined: February 9th, 2022, 12:03 pm
Contact:

Re: How Best to Use Radio Buttons With Controllers

Unread post by steve.sakhnini »

Jeff,
I see that this post is discussing two questions.
the first is how to get a selected radio button's value from a group name.
the second is a request for the ability to set the value of a radio button deferent than the label's text.
have both been answered?
word count: 52
SteveCap
Posts: 329
Joined: August 26th, 2021, 9:18 am
Contact:

Re: How Best to Use Radio Buttons With Controllers

Unread post by SteveCap »

Task #10263 has been closed and replaced with task #10266.

We are going to add a Value property to RadioButtons and Checkbox.

The existing RadioButton and CheckBox controls are going to be to create a singular radio button or checkbox. To group multiple together give them the same htmlid.

We then are going to create two new controls RadioButtonList and CheckBoxList. These will be used to create multiple. We will drop the Loop property. So you will then just need to fill out the Text and Value properties. With these new controls we will give you an ui to add static options so that the values do not always have to come from the model.

When this task is completed a new post will be made going over how to use each of the controls.
word count: 135
JustinVanRegenmorter
Posts: 576
Joined: August 26th, 2021, 9:56 am
Contact:

Re: How Best to Use Radio Buttons With Controllers

Unread post by JustinVanRegenmorter »

This issue has been resolved as of DesignTime Revision 2237 and RunTime Revision 936.
word count: 14
Post Reply