Hey Donald and Friends, As requested, snippets of the relevant classes:
class ContactInfo { /** * @orm:ManyToOne(targetEntity="Cities") * @orm:JoinColumn(name="city_id", referencedColumnName="city_id") */ private $cities; } class ContactType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $state = $this->contact_info->getCity()->getState(); $city_qb = $this->entity_manager->createQueryBuilder() ->select(array('cities', 'zip_codes')) ->from('Entity:Cities', 'cities') ->innerJoin('cities.zip_codes', 'zip_codes') ->where('cities.states = :state') ->setParameter('state', $state); $builder->add('city', 'entity', array( 'class' => 'Entity:Cities', 'query_builder' => $city_qb, 'property' => 'city_name', 'label' => 'City', )); } } On May 4, 10:38 am, Roger Webb <webb.ro...@gmail.com> wrote: > I posted this issue on the dev list as well (maybe not the right > place). > > I have a "ContactInfo" entity that has a relationship to a "City" > entity (ManyToOne). I use an "entity" type to represent the "City" in > the form. I also have a "state" field (US) which is also of the > "entity" type. When the "state" is changed I use an AJAX request to > re-populate the "city" select with cities from the selected state. > > I create the form like this: > > $contact = $em->getRepository('Entity:ContactInfo')->findByXYZ(...); > $contact_form = $this->get('form.factory')->create(new > ContactInfoType($entity_manager), $contact); > > At this point the "contact_form" is created, data is set, all is > well. > *** important ***: The "city" entity field is populated based on what > is in the database, not what was submitted. > > If the state was changed, and a city from a different state than what > was originally in the database was chosen, everything fails. The form > is invalid, and the appropriate city is not set for the Contact. This > is because the "city" choice field was populated with cities from the > previously stored state when FormFactory::create() was called and the > selected city is not an available option in the "city" field. > > I tried a messy solution to try to get around this, and passed the > state I wanted to populate the city choice with as an argument to the > constructor of ContactInfoType, but this caused the same problem, only > backwards. The new cities were populated and when it tried to > setData() on the original "contact_info" (as it was in the database), > it fails because *that* city isn't an option in the current form. > > I'm at my wits end with this one. Any ideas? please... > > Roger -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en