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 : events at initialization

Use before_init and after_init, options to set a callback before or after collection initialization.

Those callbacks will receive the current collection as argument.

Your callback doesn't require to return something.

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

Demo: click on the following button to initialize the collection.

Add, move, remove values and press Submit.

Value :a

Value :b

Value :c

Code used:

    <script type="text/javascript">

        $('#demo').click(function() {
                before_init: function(collection) {
                    alert("As you can see, there are no buttons yet...");
                after_init: function(collection) {
                    alert("Look! Now there are!!");