symfony-collection icon indicating copy to clipboard operation
symfony-collection copied to clipboard

Select2entity and Symfony-Collection

Open airv-b opened this issue 6 years ago • 1 comments

Hello, sorry to bother you. I'm trying to use this bundle select2Entity with symfony-collection, but the script doesn't seem to work with symfony-collection.

$('body').on('click', '[data-prototype]', function(e) { $(this).prev().find('.select2entity').last().select2entity(); }); https://github.com/tetranz/select2entity-bundle#embed-collection-forms

I don't understand why. And I can not tell if it's a problem with symfony-collection or select2entity.

When I use "init_with_n_elements: 1," it work but when I click on "add", the new collection doesnt have select2 in the select field.

I try this: after_add: function (collecion, element) { $('body').on('click', '[data-prototype]', function(e) { $(this).prev().find('.select2entity').last().select2entity(); }); } But it doesnt work

airv-b avatar Dec 13 '17 22:12 airv-b

I had the same probleme, i solved it like this

        after_add(collection, element) {
            let $el = $(element).find('select')
            $el.each((index, item) => {
                let $localEl = $(item)

                if ($localEl.hasClass('select2entity')) {
                    $localEl.select2entity()
                } else {
                    let $opt = select2Options($el)
                    $localEl.select2($opt)
                }
            })
        }

kl3sk avatar Apr 05 '18 08:04 kl3sk