936
Views
12
Comments
Unchecked Radio Button By Default
Question

Hi, I am working on big form and it has too many radio buttons with options Yes and No. I want none of them to be selected by default. Basically user should select Yes or No rather than no by default. I am writing form data to a  REST API and it only accepts boolean values

Thanks.  

2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello Nannu,

Are you using Radio Button widget in a Traditional Web Application?


Kind regards,

Rui Barradas

UserImage.jpg
Nannu

Rui Barradas wrote:

Hello Nannu,

Are you using Radio Button widget in a Traditional Web Application?


Kind regards,

Rui Barradas

 

Hello Rui,

I am using Reactive Web Application.

Thanks

2022-10-12 00-27-13
Ossama Ghanem
 
MVP

Hi Nannu,

Radio buttons are driven by boolean variables - which need to be either true or false. This means that there will always be a value selected.

An alternative method you can use is to create a new Static Entity called options:

And that will be the variable type that needs to be passed into the radio buttons (Entities.Options.Unselected must be set as the default value):

You'll also need to add client side validation to ensure the variable is set to either Entities.Options.True or Entities.Options.False

UserImage.jpg
Nannu

Ossama Ghanem wrote:

Hi Nannu,

Radio buttons are driven by boolean variables - which need to be either true or false. This means that there will always be a value selected.

An alternative method you can use is to create a new Static Entity called options:

And that will be the variable type that needs to be passed into the radio buttons (Entities.Options.Unselected must be set as the default value):

You'll also need to add client side validation to ensure the variable is set to either Entities.Options.True or Entities.Options.False

Hi Ossama,

I am not sure how I can map this static entity to the  boolean variable of API while retrieving data from API and Writing data to API.

Thanks

2022-10-12 00-27-13
Ossama Ghanem
 
MVP

Nannu wrote:

Ossama Ghanem wrote:

Hi Nannu,

Radio buttons are driven by boolean variables - which need to be either true or false. This means that there will always be a value selected.

An alternative method you can use is to create a new Static Entity called options:

And that will be the variable type that needs to be passed into the radio buttons (Entities.Options.Unselected must be set as the default value):

You'll also need to add client side validation to ensure the variable is set to either Entities.Options.True or Entities.Options.False

Hi Ossama,

I am not sure how I can map this static entity to the  boolean variable of API while retrieving data from API and Writing data to API.

Thanks

 

 Hi Nannu,

You can easily map the static entity to a boolean value 

e.g. (OptionID) FormVariable = if(ApiVariable=false, Entities.Options.False, Entities.Options.True)

and vice versa

e.g. (Bool) ApiVariable = if(FormVariable=Entities.Options.False, False, True)


2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello Nannu,

So you're using a Button Group widget, right? Probably, you have a boolean variable binded to the Button Group.

In order to achieve what you want, the variable binded to the Button Group can't be a Boolean. It needs to be an Integer. For example, let's say that 0 is no option selected, 1 is first option selected (NO) and 2 is second option selected (YES).

If you assign the value 0 to this variable, then none will be selected. Something like this:


Then if you select first option:


And the logic is, like I said, done using an Integer:


After this, since your API only accepts boolean values, then you just need to convert them back to a Boolean.

If the binded variable is equal to 1, then you pass False to the API. If it is equal to 2, then you pass True.


Hope that this helps you.


Kind regards,

Rui Barradas

UserImage.jpg
Nannu

Rui Barradas wrote:

Hello Nannu,

So you're using a Button Group widget, right? Probably, you have a boolean variable binded to the Button Group.

In order to achieve what you want, the variable binded to the Button Group can't be a Boolean. It needs to be an Integer. For example, let's say that 0 is no option selected, 1 is first option selected (NO) and 2 is second option selected (YES).

If you assign the value 0 to this variable, then none will be selected. Something like this:


Then if you select first option:


And the logic is, like I said, done using an Integer:


After this, since your API only accepts boolean values, then you just need to convert them back to a Boolean.

If the binded variable is equal to 1, then you pass False to the API. If it is equal to 2, then you pass True.


Hope that this helps you.


Kind regards,

Rui Barradas

 Hello Rui,

I am using Radio Button Group. How I will map this variable to the API while retrieving data from API and Writing data to API?

 Thanks

2020-05-07 18-53-00
Rui Barradas
 
MVP

Nannu wrote:

Hello Rui,

I am using Radio Button Group. How I will map this variable to the API while retrieving data from API and Writing data to API?

Thanks

 Hello Nannu,

When you are calling your server action that will call the API, you need to pass the boolean as an input parameter. So what you should do is to control this value using the variables binded to your Button Groups.


Can you please ellaborate your question?


Kind regards,

Rui Barradas 

2026-01-15 03-18-59
Vijay Malviya

Hi Nannu, 

Please find the attached .oml file .

Hope this helps you! 


Vijay M-


RadioButtonGroup.oml
UserImage.jpg
Nannu

Vijay Malviya wrote:

Hi Nannu, 

Please find the attached .oml file .

Hope this helps you! 


Vijay M-


 

 Thank you Vijay for you time. I looked at your oml and I liked this approach. As I mentioned in my original post that I am consuming Rest Api and I am not sure how I can handle mapping of this integer variable to the  boolean variable of the API on GET and POST request. And I have multiple Radio buttons so I am not sure how messy it can get.  

2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello Nannu,

Did you manage to solve your problem?


Kind regards,

Rui Barradas

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.