christusc
(Christusc)
April 15, 2014, 3:08pm
1
I am trying to use a ActiveField checkboxlist,
for example i can fill in the values by checkboxlist(array(‘PHP’,‘MySQL’,‘Javascript’)) , and it lists all these three values in my form,
but what if i want the checkbox for PHP to be checked as the form loads? how do i give the selection parameter?
It’s right there in the docs.
string checkboxList( $name, $selection = null, $items = [], $options = [] )
The second parameter should be an array of selected values.
christusc
(Christusc)
April 16, 2014, 2:50pm
3
Backslider:
It’s right there in the docs.
string checkboxList( $name, $selection = null, $items = [], $options = [] )
The second parameter should be an array of selected values.
What you have specified, is the parameters for using HTML Helper checkboxlist, what i want to use is the ActiveForm checkboxwidget.
Let me explain my scenario in detail :
in my case, i have an array called "list" which has the names of languages which will be rendered out as checkboxlist, now i am able to do that, but i want the check boxes to be checked as the form loads.
$list = [0 => 'PHP', 1 => 'MySQL', 2 => 'Javascript'];
$list2 = [0,2];
using the following line, i am able to acheive what i want using HTML helper classes :
<?= Html::checkboxList('CuisineId',$list2,$list); ?>
but i want to be able to do this using the Activeform Widget CheckboxList, which as per documentation is to be used in the following way :
static checkboxList( $items, $options = [] )
So in my case, i have figured how to pass the parameter for $items, which is in the following way:
<?= $form->field($record, 'CuisineId')->checkboxlist($list);?>
But now i do not know how to pass the parameters that will allow the checkboxes to be checked.
$record->CuisineId = $list2;
christusc
(Christusc)
April 17, 2014, 4:39am
5
Oh my god, was that so simple…wow, well it shows i haven’t got all the concepts right into my head…so much learning to do…anyways THANKS A LOT ORey!!