jFormer DocumentationBasic Fields

Multiple Choice

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.

Usage

Constructor

    new JFormComponentMultipleChoice(String id, String label, Array multipleChoiceArray[, Array optionArray])

Sample Usage

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.

', ) );

Value Returned

String if type is radio, array if type is checkbox

CSS Class

.jFormComponentMultipleChoice

Drop-Down Option Array

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.

KeyValue
value string
label string
disabled boolean
checked boolean
tip HTML

Drop-Down Options

These options are specific to the JFormComponentDropDown object.

false

disabled

boolean | determines whether or not the drop down field is disabled. A disabled drop-down list is unusable and un-clickable.

checkbox

multipleChoiceType

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.

Component Options

These options are common to all components.

null

description

HTML | a description for the component, shows underneath the component inside a DIV with the class jFormComponenpescription.

null

instanceOptions

Array, [max(int), addButtonText(string), removeButtonText(text)] | see instanceOptions page for more information.

null

dependencyOptions

Array, [dependentOn(string), display(string), jsFunction(Javascript)[, animationOptions(array)]] | see dependencyOptions page for more information.

null

triggerFunction

Javascript | a javascript function that runs upon component change.

null

tip

HTML | a tooltip that displays whenever the component has focus. Gives any extra help or explanation a form user might need.

null

validationOptions

Array | an of validations specific to the component, see the specific component for its validations.

false

showErrorTipOnce

Boolean | this option makes the error tip only show up on the first focus on the component if it does not pass validation.

false

enterSubmits

Boolean | if true pressing enter while this component has focus submits the form, or advances to the next page.

null

style

CSS | set the style attribute for the component wrapper div.

null

initialValue

String | preset the value of the component upon form loading.

Multiple Choice Validation Options

NameError 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)

Ced W on 2011-04-27 09:02:24

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;

rafael on 2012-04-01 04:28:54

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'),

)),

rafael on 2012-04-01 04:29:47

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'),

)),