I have encountered one problem regarding radio buttons in my current project. please see the attached image below…
In this image the option 1 & option 4 is disabled or deactivated. That mean user can select any one from the Option 2, Option 3 & Option 5. but user cannot select Option 1 & Option 2.
Can we implement the same in Servoy by using the radio button?
As far as I am aware, there is only one way to represent this and that is to show this same dataprovider 5 separate times on the form using a different valuelist for each instance to denote each radio choice
As you then have separately named objects then you can address editable properties onShow or onRecordSelect etc for each one
Harry Catharell:
As far as I am aware, there is only one way to represent this and that is to show this same dataprovider 5 separate times on the form using a different valuelist for each instance to denote each radio choice
Hi Harry,
Yes, we can do that by using the same dataprovider 5 times. but is not it quite annoying.
If there are number of options, then it will be quite quite annoying.
However, at least you do gain object control over each individual value list item
One other option would be to programnmatically load the valuelist based on your condition and only show the available options.
So if you only want to show b, c & e then you only load those options into the value list and simply don’t show a & d at all
You can do this with one value list and I can see some UI advantages to showing the disabled options. So this is an extra way to do it besides what Harry suggested with not showing disabled values (which may be more appropriate depending on your situation).
Create your value list on the onRecordSelect event if the value list items that will be disabled will be different from record to record. The value list will need a display item and a stored item for each value.
For the display item, use HTML. If it is a disabled value, set the font color to something light grey. Here’s an example result:
Then create a method for the onDataChange event of the field and set the field to null if a “disabled” value is selected:
/*****
don't allow a disabled item to be checked
*****/
//get value list visible item
var visible = application.getValueListDisplayValue("vl_category", category)
//if there is a <font> tag it is not a valid option
if (visible.search(/font/) > 0) {
category = null
}
What is cool is that if the value of “Books” (in this example) is in the field already, it will show up in the radio field even though that selection is currently “disabled”. So your enable/disable rules can change over time but your data won’t change.