shtumi / ShtumiUsefulBundle

Symfony 2 bundle with some useful things - custom form types, dql functions, twig extensions, etc...
110 stars 68 forks source link

Select control duplicate #67

Open duvg opened 8 years ago

duvg commented 8 years ago

I'm use this bundle is excellent but i have a error, when load its in select dependent, where mi parent is Category and my chind control is Product, it's work perfect but have a bug, on duplicate control product

this is my code config

shtumi_useful:
    dependent_filtered_entities:
        producto_by_categoria:
            class: GestionBundle:Producto
            parent_property: categoria
            property: nombreciud
            role: IS_AUTHENTICATED_ANONYMOUSLY
            no_result_msg: 'No hay regiones encontradas'
            order_property: nombreciud
            order_direction: ASC`

this is mi code from my admin class selecction where implement this functionality

$formMapper
            ->add('codigo','text', array('label'=>'codigo', 'required'=>'true'))
            ->add('categoria')
            ->add('productos')
            ->add('productos', 'shtumi_dependent_filtered_entity', array(
                'entity_alias' => 'producto_by_categoria',
                'empty_value' => 'Select',
                'parent_field' => 'categoria',
                'required' => true,

            ))
        ;

bug

help me pease!

anacona16 commented 8 years ago

Hi @duvg the problem isn't this bundle, the problem is the select2 library used by Sonata.

My solution was make a call to setup_select2() function after the ajax call.

$(document).ajaxSuccess(function (event, xhr, settings) {
    Admin.setup_select2();
});