Choice
Choice field is hybrid type, because it can be:
- Regular select
- Select with multiple choices
- List of radio buttons
- List of checkboxes
<?php
// This creates list of checkboxes
$this->add('languages', 'choice', [
'choices' => ['en' => 'English', 'fr' => 'French'],
'choice_options' => [
'wrapper' => ['class' => 'choice-wrapper'],
'label_attr' => ['class' => 'label-class'],
],
'selected' => ['en', 'fr'],
'expanded' => true,
'multiple' => true
]);
Beside inherited, there are some additional options available:
choices
(Array
) (Default:[]
) - key value pairs that will be used in the listchoice_options
(Array
) (Default:['wrapper' => false]
) - Options that will be provided to each choice entryselected
(String|Array|Closure
) (Default:null
) - Item that needs to be selected/checked, if not provided fetched from Modelexpanded
(Boolean
) (Default:false
) - If true, list will be of type radios or checkboxes(depending on multiple option)multiple
(Boolean
) (Default:false
) - If true, allows multiple select or list of checkboxes (depending on expanded option)
expanded | multiple | Field type |
---|---|---|
false | false | Select |
false | true | Select with multiple attribute |
true | false | List of radio buttons |
true | true | List of checkboxes |
selected
can be modified with Closure the same way like in Select field type