phiamo/MopaBootstrapBundle — pull request #87 by pierroweb (2012-04-17 00:36:45+00:00)
Title: fix the index counter when using 'allow_add'=>true for embedded forms

Issues
-----------------------------
The add button is not working here, the index instantiated is almost always incorrect (always equal to 0).

In the constructor there https://github.com/phiamo/MopaBootstrapBundle/blob/v2.x_sf2.0/Resources/public/js/mopabootstrap-collection.js#L30, the value

this.options.collection_id

is not set

Looking at https://github.com/phiamo/MopaBootstrapBundle/blob/v2.x_sf2.0/Resources/public/js/mopabootstrap-collection.js#L68 it seems that the option object doesnt contain collection_id (and I dont get how you define options???)

I also dont understand why calling length on $('.collection.controls') to calculate this.options.index in https://github.com/phiamo/MopaBootstrapBundle/blob/v2.x_sf2.0/Resources/public/js/mopabootstrap-collection.js#L30.

This is the parent, and the index should be the number of embedded forms, something like:

$('.collection.controls > .collection.controls > div.collection-item').length - 1

PR
-------------------------------------
this code is working here and resolves the issues above.

Please propagate the change to v2.x_sf2.0 as well !