Problems when making dependent select boxes

0

Good, I have problems making select dependent on another. I've tried with:

link

But I have not managed to make it work, the problem is that they relate to several entities but what I want is to relate to a single entity.

These two variables I need to create a form where they are select. Both will have information of two variables of an entity. But one depends on another (version depends on year), where there will be several versions but each one is one year old. Versions related to the year are displayed.

/**
 * @var string
 *
 * @ORM\Column(name="año", type="string", nullable=true)
 */
private $anio;

/**
 * @var string
 *
 * @ORM\Column(name="version", type="string", nullable=true)
 */
private $version;
    
asked by Ricardo Etcheverry 23.11.2016 в 13:41
source

1 answer

0

Use this Bundle works with Symfony 3.x and there is also support for Symfony 2.x with this Bundle First you must install some dependencies like BraincraftedBootstrapBundle The detail of the installation here

An example of the use, this goes inside the Form and depends on the entities that you are using:

$builder
   ->add('country', Select2EntityType::class, [
            'multiple' => true,
            'remote_route' => 'tetranz_test_default_countryquery',
            'class' => '\Tetranz\TestBundle\Entity\Country',
            'primary_key' => 'id',
            'text_property' => 'name',
            'minimum_input_length' => 2,
            'page_limit' => 10,
            'allow_clear' => true,
            'delay' => 250,
            'cache' => true,
            'cache_timeout' => 60000, // if 'cache' is true
            'language' => 'en',
            'placeholder' => 'Select a country',
            // 'object_manager' => $objectManager, // inject a custom object / entity manager 
        ])

You must first place the use to the Bundle:

use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;

For more detail of everything you can do here

    
answered by 29.06.2017 в 22:24