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).

JavaScript options : minimum and maximum of collection elements

Use min and max options to define limits on the number of elements in the collection.

The example below shows you a collection having from 2 to 5 elements.


This demostration is made of the following files (click to see on GitHub in a new tab):
    -     Controller/OptionsController.php
    -     Resources/views/Options/numberCollectionElements.html.twig
    -     Resources/views/Options/options-theme.html.twig

A simple collection

Add button will disappear if your collection has 5 elements, and Remove button if your collection has 2 elements.

Value : a

Value : b

Value : c

A collection of themed types

On a themed type, elements having collection-add class will be hidden if your collection has 5 elements, and elements having collection-remove class if your collection has 2 elements.

Value : a

Value : b

Value : c


Code used:

    <script type="text/javascript">

        $('.form-collection, .advancedForm-collection').collection({
            min: 2,
            max: 5
        });

    </script>