Ramin Firooz
Ramin Firooz

Reputation: 506

Lithium: Correct use of select2 with `multiple` option

by using Lithium form helper we can insert a select tag that a single item can be selected.

sample:

echo $this->form->field('myfield', array(
    'type' => 'select',
    'list' => array(
        'id1' => 'value1',
        'id2' => 'value2',
        ),
    )
);

Now if you want to use Select2 jQuery plugin with multiple option, field method in form helper tries to retrieve submitted value in string. even when multiple option is set!

non-working sample:

echo $this->form->field('myfield', array(
    'type' => 'select',
    'list' => array(
        'id1' => 'value1',
        'id2' => 'value2',
        ),
    'multiple' => true,
    )
);

Upvotes: 0

Views: 63

Answers (1)

Ramin Firooz
Ramin Firooz

Reputation: 506

field method won't accept array value in submitted forms.

so try select method in Form Helper with a multiple option.

sample code:

echo $this->form->select('myfield', 
    array(
         'id1' => 'value1',
         'id2' => 'value2',
    ),
    array(
        'multiple' => true,
    )
);

Upvotes: 0

Related Questions