Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"given collection selector does not exist." on nested collection without initialized elements #152

Open
Wait4Code opened this issue Sep 16, 2019 · 1 comment

Comments

@Wait4Code
Copy link

Hi,
It seems that with nested collection, if parent collection is not initialized with any elements, there is the "given collection selector does not exist." message about sub-collection selector.

Anyway, parent AND child collections are working correctly but this message disturbs me.

Here pieces of code :

    let config = {
        name_prefix: '',
        allow_up: false,
        allow_down: false,
        allow_add: true,
        allow_remove: true,
        allow_duplicate: false,
        add: '<a href="#" class="btn btn-success"><i class="fas fa-plus-circle"> </i></a>',
        remove: '<div class="col-12"><a href="#" class="btn btn-danger"><i class="fas fa-minus-circle"> </i></a></div> ',
        init_with_n_elements: 0,
        drag_drop: false,
        add_at_the_end: true,
        children: [{
            selector: '.js-child-collection',
            add: '<a href="#" class="btn btn-success btn-sm"><i class="fas fa-plus-circle"> </i></a>',
            remove: '<div class="col-12"><a href="#" class="btn btn-danger btn-sm"><i class="fas fa-minus-circle"> </i></a></div> ',
            allow_up: false,
            allow_down: false,
            allow_add: true,
            allow_remove: true,
            allow_duplicate: false,
            init_with_n_elements: 0,
            drag_drop: false,
            add_at_the_end: true,
        }]
    };
$('.js-collection[data-type="environment"]').collection(config);

Root FormType :

// ...
            ->add('environments', CollectionType::class, [
                'entry_type' => EnvironmentType::class,
                'entry_options' => ['label' => false],
                'attr' => [
                    'class' => 'js-collection',
                    'data-type' => 'environment'
                ],
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
                'prototype' => true,
                'required' => false,
            ])
// ...

EnvironmentType :

//...
            ->add('webAccesses', CollectionType::class, [
                'entry_type' => WebAccessType::class,
                'entry_options' => ['label' => false],
                'attr' => ['class' => 'js-child-collection'],
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
                'prototype' => true,
                'prototype_name' => '__parent_name__',
                'required' => false,
                'mapped' => false,
            ])
//...
@pdhuaman
Copy link

If you are using form themes, the collectionType input must be within the block of the collection parent.

{% block parent_type_widget %}
{{ form_row(...) }}
...
...
{{form_row(form.child_collection) }}
{% endblock parent_type_widget %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants