Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3918

Symfony 4 Twig Custom Form Field Template For Collection Of Checkboxes

$
0
0

I've used a custom template no problem when using a collection of checkboxes to change the html to be in a table like this:

{% form_theme form _self %}

{% block _packing_dispatch_form_group_formsA_0_packagingList_widget %}
    <div {{ block('widget_container_attributes') }}>
        <div class="table-responsive">
            <table>
                {%- for child in form %}
                    <tr>
                        <td class="firstCol">{{- form_label(child, null, {translation_domain: choice_translation_domain}) -}}</td>
                        <td>{{- form_widget(child) -}}</td>
                    </tr>
                {% endfor -%}
            </table>
        </div>
    </div>
{% endblock %}

But now the collection has changed so it holds a collection of another form type which then holds the checkboxes, i can't figure out how i now apply the same template to the new collection of the second form type.

Here is the code:

PackagingDispatchFormGroupType.php

$data= [];
            $packingForm = new PackingDispatchForm();
            $data[] = $packingForm;

            $builder->add('formsA', CollectionType::class,[
               'entry_type'=>PackingDispatchFormType::class,
                'entry_options'=>[
                    'user'=>$this->user
                ],
                'allow_add'=>true,
                'allow_delete'=>true,
                'data'=>$data,
                'mapped'=>false
            ]);

PackagingDispatchFormType.php

->add('packagingList',ChoiceType::class,[
                'multiple'=>true,
                'expanded'=>true,
                'attr'=>[
                    'class'=>'packagingListInput'
                ],
                'choices'=>[
                    'Digitherm Camera, CDX8950-400' => 'Digitherm Camera, CDX8950-400',
                    'Battery, CDX370PACK' => 'Battery, CDX370PACK',
                    'Battery Tab, CDX8950-514' => 'Battery Tab, CDX8950-514',
                    'Memory Card, CDX8IS' => 'Memory Card, CDX8IS',
                    'Memory Card Reader, CDXUSBR' => 'Memory Card Reader, CDXUSBR',
                    'Charging Station, CDX370D' => 'Charging Station, CDX370D',
                    'Power Supply (3x Adapters), CDX370C' => 'Power Supply (3x Adapters), CDX370C',
                    'Australian Adapter' => 'Australian Adapter',
                    'Access Key, XP-100' => 'Access Key, XP-100',
                    'Wrist Strap, CDX8950-550' => 'Wrist Strap, CDX8950-550',
                    'Fragrance Card, CDX8950-512' => 'Fragrance Card, CDX8950-512',
                    'Accessory Card' => 'Accessory Card',
                    'Instructions For Safe User, CDX8950-511 Rev. A' => 'Instructions For Safe User, CDX8950-511 Rev. A',
                    'User Manual, CDX8950-507, Rev. A' => 'User Manual, CDX8950-507, Rev. A',
                    'Battery Warning Card' => 'Battery Warning Card',
                    'Charger Instruction Leaflet' => 'Charger Instruction Leaflet',
                    'Declaration Of Conformity, SOM15, Rev. A' => 'Declaration Of Conformity, SOM15, Rev. A'
                ],
                'disabled'=>($this->forView ? true : false),
                'choice_attr'=>function($choice, $key, $value){
                    return ['required'=>true];
                },
                'invalid_message'=>'All Of The Packaging List Checkboxes Are Required'
            ]);

The whole point here is that i can now duplicate the form field as an array of the checkboxes, but can't seem to apply the same html template.


Viewing all articles
Browse latest Browse all 3918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>