vendredi 2 juin 2017

CheckBox for multiple choice php - Symphony

I tried to create a checkBox for multiple choice. This question is duplicate enter link description here

This following my code:

->add('Article', 'choice', array(

'choices' => array('A' => 'B',
                        'B' => 'B',
                        'C' => 'C',
                        'D' => 'D',
                        'OTHERS' => 'OTHERS'),

                        'required' => FALSE,
                        'empty_value' => 'ALL',
                        'empty_data' => NULL,                   
                        'multiple' => true,
                        'expanded' => true,
                        'choice_label' => function ($value, $key, $index) {
                        if ($value == true) {
                        return $key;
                        }},
                        'choice_attr' => function($value, $key, $index) {
                        return $key;
                        },

@Hatef enter link description here suggested me to add expanded, multiple and to set them to true, also to add choice_attr or choice_label.

When I add expanded and multiple the CheckBOx list dispaly next to each other not like this:enter image description here

And when I add choice_label or choice_attr, I got this error:

    UndefinedOptionsException in OptionsResolver.php line 745:
    The option "choice_attr" does not exist. Known options are: "action",
    "attr", "auto_initialize", "block_name", "by_reference", "choice_list", "choices", 
    "compound", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "empty_value",
    "error_bubbling", "expanded", "inherit_data", "intention", "label", "label_attr", 
   "label_format", "mapped", "max_length", "method", 
   "multiple", "pattern", "placeholder", "post_max_size_message", "preferred_choices",
   "property_path", "read_only", "required", "translation_domain", "trim", "virtual".

Please How can I change my code to get a checkBox for multiple choice like in this picture ?

Thank you.




Aucun commentaire:

Enregistrer un commentaire