KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Grouping Dynamically Generated Radio Buttons
PRODUCT: 4D | VERSION: 16R6 | PLATFORM: Mac & Win
Published On: February 22, 2018

Radio Buttons typically come in counts of greater than one (1) and provide users a list of choices in which the user needs to select only one of. Radio buttons will deselect any other choice if a different button was selected. In 4D, this is controlled by grouping the radio buttons. When duplicating radio buttons with the OBJECT DUPLICATE command, they can be grouped by declaring the name of an object in an existing group in the boundTo parameter.

If a radio button is duplicated and not bound to another radio button in a group it will not be part of any groups and if bound to a radio button not in a group it will simply set the entry order. Thus any dynamically created groups of radio buttons must already be on the form.

In v16R6 a new feature, that allows dynamically generated forms with the DIALOG command, allows groups of radio buttons to be generated without any preexisting groups. When an object is of the type "radio" it can also utilize the "radioGroup" attribute to declare a group name. Any radio buttons with the same group name will be part of the same group.

Example:

//Create Yes Radio Button
$rb1_b:=New object("text";"Yes";"top";20;"left";20;"width";150;"height";20)
$rb1_b.type:="radio"
$rb1_b.radioGroup:="radioYN"

//Create No Radio Button
$rb2_b:=New object("text";"No";"top";45;"left";20;"width";150;"height";20)
$rb2_b.type:="radio"
$rb2_b.radioGroup:="radioYN"

//Add radio buttons to Page 1
$page1_o:=New object("objects";New object("rb1";$rb1_b;"rb2";$rb2_b))

//Add Page 1 to Form
$form_o:=New object("rightMargin";20;"bottomMargin";20)
$form_o.pages:=New collection(Null;$page1_o)

// Load the form dialog
$win_l:=Open form window($form_o)
DIALOG($form_o)


Running the code will generate the following:


Dynamically generated forms can also be applied to Subforms using the OBJECT SET SUBFORM command, thus allowing dynamic radio buttons to also be added to prebuilt forms as long as there is a subform container on the form.