Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony 2.1: Dynamic drop-down that depend on another entity
    primarykey
    data
    text
    <p>I'm working with Symfony2 and here is my problem: I have 3 entities, Category, Subcategory, and Article. A category can have many sub categories, and each subcategory can have many articles. So there is a bidirectionnal oneToMany relationship between Category and SubCategory, as well as between SubCategory and Article. This design is a constraint, and I cannot change it.</p> <p>I have to make a form for editing Articles, in which the user has to select the category, and then the subcategory the article belongs to. </p> <p>However, I cannot find how to have the list of the subcategories to be dynamically updated when the user changes the vaues of the Category dropdown. The subcategory dropdown should ony display the subcategories linked to the current category.</p> <p>I already made a form type for editing the articles :</p> <pre><code>class ArticleType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder -&gt;add('domain', new SubCategoryPickerType()) -&gt;add('title') -&gt;add('description') -&gt;add('content') ; } // ... </code></pre> <p>Then I started making the form for getting an entity based on 2 dropdown lists :</p> <pre><code>class DomainPickerType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder -&gt;add('category') -&gt;add('name', 'entity', array( 'class' =&gt; 'Htbf\CoreBundle\Entity\SubCategory', 'property' =&gt; 'name')) ; // ... </code></pre> <p>The problem is that like this, the 2 dropdown do not depend on each other : the 2nd one is not updated when the first one is changed, and the second one contains all the possibilities of subcategories, not the one associated to the current category.</p> <p>Any idea how to do that ? Thanks in advance !</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload