I have a form that I have built in symfony2.
$builder->add('purchaseOrder','text');
$builder->add('product', 'entity', array(
'class' => 'WICProductBundle:Product',
'property' => 'name',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('p')
->where('p.account=?1')
->orderBy('p.name', 'ASC')
->setParameter(1,$this->account);
}
));
When I output this form in Twig and submit it, it works fine!
When I change my form builder to this and submit the form, I get an error?!?!
$builder->add('purchaseOrder','text');
$builder->add('product','text');
The first iteration of the form I fill in the purchase order field with 8 and I select an option in the product drop down with the value of 65... All works well...
The second iteration of the form I fill in the purchase order field with 8 and I fill in the product field with the value of 65... And I get this error:
Catchable Fatal Error: Argument 1 passed to WIC\PurchaseOrderLineItemBundle\Entity\PurchaseOrderLineItem::setProduct() must be an instance of WIC\ProductBundle\Entity\Product, string given, called in /Applications/MAMP/htdocs/symfonydev/vendor/symfony/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 538 and defined in /Applications/MAMP/htdocs/symfonydev/src/WIC/PurchaseOrderLineItemBundle/Entity/PurchaseOrderLineItem.php line 302
Why would my form break from a swapping out a drop down to a text box if the same value of "65" is being passed each time?