Skip to content

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

@Wait4Code

Description

@Wait4Code

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,
            ])
//...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions