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.
Hello Nannu,
Are you using Radio Button widget in a Traditional Web Application?
Kind regards,
Rui Barradas
Rui Barradas wrote:
Hello Rui,
I am using Reactive Web Application.
Thanks
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
Ossama Ghanem wrote:
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.
Nannu wrote:
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)
Please see these posts that can help you:
https://www.outsystems.com/forums/discussion/19333/radio-button/#Post74968
https://www.outsystems.com/forums/discussion/41059/by-default-both-radio-buttons-should-be-unchecked/#Post147589
BR,
Luis
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.
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?
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?
Please find the attached .oml file .
Hope this helps you!
Vijay M-
Vijay Malviya wrote:
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.
Did you manage to solve your problem?