How Best to Use Radio Buttons With Controllers
-
- Posts: 178
- Joined: August 31st, 2021, 11:37 am
- Contact:
How Best to Use Radio Buttons With Controllers
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?
Last edited by JefferyD on March 18th, 2022, 4:58 pm, edited 1 time in total. word count: 101
Tags:
-
- Posts: 40
- Joined: February 9th, 2022, 12:03 pm
- Contact:
Re: How Best to Use Radio Buttons With Controllers
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: or with JQuery:
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.
ex:
Code: Select all
document.querySelector("input[name='some_shared_name']:checked").value
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
-
- Posts: 178
- Joined: August 31st, 2021, 11:37 am
- Contact:
Re: How Best to Use Radio Buttons With Controllers
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
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.
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
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
-
- Posts: 47
- Joined: September 7th, 2021, 1:04 pm
- Contact:
Re: How Best to Use Radio Buttons With Controllers
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 Default Text.png (5.06 KiB) Viewed 2097 times
- Classic Radio Button Default Text.png (5.06 KiB) Viewed 2097 times
word count: 31
-
- Posts: 40
- Joined: February 9th, 2022, 12:03 pm
- Contact:
Re: How Best to Use Radio Buttons With Controllers
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.
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
-
- Posts: 40
- Joined: February 9th, 2022, 12:03 pm
- Contact:
Re: How Best to Use Radio Buttons With Controllers
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?
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
-
- Posts: 329
- Joined: August 26th, 2021, 9:18 am
- Contact:
Re: How Best to Use Radio Buttons With Controllers
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.
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
-
- Posts: 571
- Joined: August 26th, 2021, 9:56 am
- Contact:
Re: How Best to Use Radio Buttons With Controllers
This issue has been resolved as of DesignTime Revision 2237 and RunTime Revision 936.
word count: 14