0

I am trying to use a CheckBoxType in a form inside a CollectionType but the prototype only contains the label and no checkbox at all !

This is really weird; I don't understand because the symfony documentation here does not mention anything special to do ?

When I click on the button to add a new file I only get the label

What am I missing please?

THE COLLECTION

->add('file', CollectionType::class, array(
    'label' => false,
    'entry_type' => FileType::class,
    'error_bubbling' => false,
    'entry_options' => [ 'required' => false, 'error_bubbling' => true, ],
    'allow_add' => true,
    'allow_delete' => true
))

THE CHECKBOX INSIDE FILETYPE

->add('main', CheckboxType::class,[
     'label'    => 'Make this one the main picture',
     'required' => false,
]);

THE RESULTING PROTOTYPE

data-prototype="<div id=\"new_item_group_pictures_itemFile___name__\">    <div class=\"form-item\"><div class=\"form-label\"></div><div class=\"custom-select\"><input type=\"file\" id=\"new_item_group_pictures_itemFile___name___file\" name=\"new_item[group_pictures][itemFile][__name__][file]\" class=\"form-file\" /></div></div>    <div class=\"form-item\"><div class=\"form-label\"><label for=\"new_item_group_pictures_itemFile___name___description\">Description</label></div><input type=\"text\" id=\"new_item_group_pictures_itemFile___name___description\" name=\"new_item[group_pictures][itemFile][__name__][description]\" maxlength=\"255\" class=\"form-input form-text\" /></div>    <div class=\"form-item\"><div class=\"form-label\"><label for=\"new_item_group_pictures_itemFile___name___main\">Make this one the main picture</label></div></div></div>"

ENTITY PROPERTY

 /**
 * @var boolean
 * @ORM\Column(type="boolean", nullable=true)
 */
private $main;
2
  • Try using 'label' => false inside entry_options's array. Commented Dec 27, 2018 at 22:29
  • I tried but no change Commented Dec 27, 2018 at 23:26

2 Answers 2

1

you have to render your embeded form collection iterating over it:

{% for t in form.file %}
    {{ form_row(t) }}
{% endfor %}

This will render each checkbox and you can manipulate them in your view

Normally checkboxType should work fine, but if you want to try another solution you can set your second form to ChoiceType and add expanded (to expand choices like checkboxes) and multiple true.

->add('main',  ChoiceType::class,[
     'label'    => 'Make this one the main picture',
     'required' => false,
     'choices' => array(),
     'expanded' => true,
     'multiple' => true
]);
Sign up to request clarification or add additional context in comments.

Comments

0

The label of the collection type should be true and when you render the form field of the collection type use form_widget instead of form_row

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.