Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use select box related on another select box?
    primarykey
    data
    text
    <p>How to use related select boxes in Symfony ?</p> <p>Let's say, I have a select list containing compagnies and another containing employees of the selected company. How do I define those in Symfony? I have already created all the Javascript related code but when submitting my form and having errors on some fields, the all "sub" select fields are reset to null. </p> <p>Any ideas?<br> Thanks, </p> <p>EDIT : As the question seems to be misunderstood, I'll add some precisions :</p> <h2>Description :</h2> <ol> <li>I have an entity Company containing a list of Employees using a @OneToMany relation.</li> <li>When I select a company in a select/dropdown list, the second dropdown list containing the employees is updated via jQuery. <strong>That part is done, works perfectly</strong></li> <li>When submitting the form without errors, the entity form solution works fine. </li> <li>When submitting the form containing errors, the second dropdown list is containing <strong>all</strong> possible values. They are not filtered on the selected company. </li> </ol> <h2>Tried solutions :</h2> <ul> <li>My first idea was to use the <strong>form entity</strong> type, thinking the component could be binded somehow on another field. ie. update list of employees based on the value of the selected company. </li> </ul> <p><em>Not working, there is no way out of the box to do this. Even non out of the box solutions...</em> </p> <ul> <li>Then I thought about <strong>manually passing</strong> the selected company as <strong>parameter</strong> to the query builder of the second dropdown list. </li> </ul> <p><em>But when the form is created, the values are empty. The values are only set on <strong>bindRequest</strong>.</em></p> <ul> <li>Thought about using the choice type. Delegating all filter functionnality to the UI via Javascript. Meaning when the page loads, an empty list appears and is populated by Javascript based on the selected company.</li> </ul> <p><em>This actually works, but I think there is no other word than really <strong>really ugly programming</strong> here.</em></p> <h2>PS :</h2> <p>Question has been asked here, on the Symfony2 mailing-list, on Twitter and the officiel Symfony 2 forum. I have of course searched each of those several times before posting my questions. </p>
    singulars
    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.
 

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