Yellow Flag

This website version is not maintained anymore

Up to date documentation is available in Symfony 3.x website (see the dropdown menu above).

Advanced usage: MVC compliance

In the Basic Usage example, we defined the collection's selector in the form type, but that's not a good practice, as a selector should take part of the view.

You can reference your form collection using any container, such as a <div>, and setting data-collection="{{ form.collectionField.vars.id }}".


This demostration is made of the following files (click to see on GitHub in a new tab):
    -     Controller/AdvancedController.php
    -     Resources/views/Advanced/mvcCompliance.html.twig
Add, move, remove values and press Submit.
Value
Value
Value

Value :a

Value :b

Value :c


Code used:

    <!-- Note that data-collection="(...)" was generated by the form component, I useddata-collection="{{ form.values.vars.id }}" -->
    <div class="i-am-a-collection" data-collection="form_values"></div>

    <script type="text/javascript">
        $('.i-am-a-collection').collection();
    </script>