jFormer Documentation → Basic Fields →
JFormComponentMultipleChoice(String id, String label, Array multipleChoiceArray[, Array optionArray])
The Multiple Choice field presents a list of choices to the user, allowing them to select one or more of the options depending on the Multiple Choice field type.
new JFormComponentMultipleChoice(String id, String label, Array multipleChoiceArray[, Array optionArray])
Create a multiple choice component with a tooltip and choice tooltip:
$multipleChoice = new JFormComponentMultipleChoice('id', 'Label:',
array(
array(
'value' => 'choice1',
'label' => 'Choice 1'
),
array(
'value' => 'choice2',
'label' => 'Choice 2'
'tip' => 'This is a tip for a specific choice.
'
),
),
array(
'tip' => 'This is a tooltip on a multiple choice component.
',
)
);
String if type is radio, array if type is checkbox
.jFormComponentMultipleChoice
The Multiple Choice array is an array of arrays that sets the value labels and attributes of each of the options within the dropdown. it has the following key/value pairs see the example above for a usage example.
| Key | Value |
| value | string |
| label | string |
| disabled | boolean |
| checked | boolean |
| tip | HTML |
These options are specific to the JFormComponentDropDown object.
false
boolean | determines whether or not the drop down field is disabled. A disabled drop-down list is unusable and un-clickable.
checkbox
string | one of two types, checkbox or radio, set the multiple choice component as either one. radio allows only one item to be selected, while checkbox allows multiple.
These options are common to all components.
null
HTML | a description for the component, shows underneath the component inside a DIV with the class jFormComponenpescription.
null
Array, [max(int), addButtonText(string), removeButtonText(text)] | see instanceOptions page for more information.
null
Array, [dependentOn(string), display(string), jsFunction(Javascript)[, animationOptions(array)]] | see dependencyOptions page for more information.
null
HTML | a tooltip that displays whenever the component has focus. Gives any extra help or explanation a form user might need.
null
Array | an of validations specific to the component, see the specific component for its validations.
false
Boolean | this option makes the error tip only show up on the first focus on the component if it does not pass validation.
false
Boolean | if true pressing enter while this component has focus submits the form, or advances to the next page.
null
CSS | set the style attribute for the component wrapper div.
null
String | preset the value of the component upon form loading.
| Name | Error Message and Description |
| required |
"required." The 'required' validation makes sure that there is a value selected.
'validationOptions' => array('required'),
|
| minOptions |
"You must select more than [minimum] options." The 'minOptions' makes sure you have at least a certain number of checkboxes selected.
'validationOptions' => array('minOptions' => 3),
|
| maxOptions |
"You must select more than [maximum] options." The 'maxOptions' makes sure you have at least a certain number of checkboxes selected.
'validationOptions' => array('maxOptions' => 3),
|
Next Page: Single Line Text
This page was last edited on April 25, 2011 at 1:21pm.
6 comments (add a comment)
How do you set up the checkbox as array? I just need an example of how to set up the checkboxes and I'm good.
farzher on 2012-01-04 13:38:14
How do you set the 'initialValue' of radio buttons?
farzher on 2012-01-04 13:38:38
How do you set the 'initialValue' of radio buttons?
Mike Pearce on 2012-02-22 19:34:40
There is an error in the jFormer.js for this component.
In JFormComponentMultipleChoice::initialize -> 'minOptions', around line 5271, change minOptions function code to read:
var errorMessageArray = ['You must select at least ' options.minOptions ' options'];
return options.value.length >= options.minOptions ? 'success' : errorMessageArray;
initialValue of radio buttons? is this the only way out:
$pyt_a2_2 = true;
new JFormComponentMultipleChoice('a2', 'A2 Do you think that the company you work for provides services in competitive manner?',
array(
array('value' => '5', 'label' => 'Yes', 'sublabel' => '5', 'checked' => $pyt_a2_1),
array('value' => '4', 'label' => 'Rather yes', 'sublabel' => '4', 'checked' => $pyt_a2_2),
array('value' => '3', 'label' => 'Neither yes, nor no', 'sublabel' => '3', 'checked' => $pyt_a2_3),
array('value' => '2', 'label' => 'Rather no', 'sublabel' => '2', 'checked' => $pyt_a2_4),
array('value' => '1', 'label' => 'No', 'sublabel' => '1', 'checked' => $pyt_a2_5),
),
array(
'multipleChoiceType' => 'radio',
'validationOptions' => array('required'),
)),
initialValue of radio buttons? is this the only way out:
$pyt_a2_2 = true;
new JFormComponentMultipleChoice('a2', 'A2 Do you think that the company you work for provides services in competitive manner?',
array(
array('value' => '5', 'label' => 'Yes', 'sublabel' => '5', 'checked' => $pyt_a2_1),
array('value' => '4', 'label' => 'Rather yes', 'sublabel' => '4', 'checked' => $pyt_a2_2),
array('value' => '3', 'label' => 'Neither yes, nor no', 'sublabel' => '3', 'checked' => $pyt_a2_3),
array('value' => '2', 'label' => 'Rather no', 'sublabel' => '2', 'checked' => $pyt_a2_4),
array('value' => '1', 'label' => 'No', 'sublabel' => '1', 'checked' => $pyt_a2_5),
),
array(
'multipleChoiceType' => 'radio',
'validationOptions' => array('required'),
)),