简体   繁体   中英

How to dynamically modify a form field based on 2 other fields in Symfony?

The Symfony documentation explains how to add a field based on the value of an other field for a submitted form: http://symfony.com/doc/2.3/cookbook/form/dynamic_form_modification.html#cookbook-form-events-submitted-data

However, how to add a field based on the value of 2 other fields?

Let's say I have these 3 fields in my form:

  • Category
  • Brand
  • Model

Each of these fields are entity fields, but only brands of the selected category should be shown (easily done with the mentioned cookbook, using the FormEvents::POST_SUBMIT event), and only models of the selected category and brand (if they are both submitted) should be shown in the list.

This means that I need to get the submitted values of both the brand and the model to get the list of available models.

How can I achieve that?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM