In the following example, Office has a many-to-many with Contact.
When attempting the same approach in functional tests, e.g. by doing:
$form = $buttonCrawlerNode->form(array(
'company_whateverbundle_officetype[office_contacts][contact]' => '1'
The actual result is:
InvalidArgumentException: The form field "company_whateverbundle_officetype[office_contacts][contact]" does not exist.
The expected result is that a new contact is added.
Steps to reproduce:
Same deal with collections of "file" entities when calling:
Are you setting the allow_add option to true for the CollectionType ?
Yes, it works fine in dev/prod environments.
Hi @gzankevich, did you managed it?
Issue still persists. I'll try it out on a clean installation and see what happens.
I am facing the same problem.
@gzankevich Did you find what happend?
I've created a Gist containing all of the code necessary to reproduce the problem: https://gist.github.com/3193910
I'll try submitting the form with a $client->request('POST', $data).
Not optimal, but it should at least let me test the controller.
I was facing this problem to today, I actually needed to remove a row from the collection 😄
But found I little trick to make this work.
$form = $crawler->selectButton('save')->form();
'customer_invoice_form[customer]' => 'C0001',
'customer_invoice_form[address]' => "274 Rose avenue US\n212-35 OKMontgomery",
'customer_invoice_form[items][number]' => 1,
'customer_invoice_form[items][label]' => 'Domainreg bar-foo.com',
'customer_invoice_form[items][period][start]' => '01-01-2013',
'customer_invoice_form[items][period][end]' => '01-12-2013',
'customer_invoice_form[items][price]' => '20,00',
'customer_invoice_form[items][taxPercent]' => '21,10',
// Now do what ever you want with the $values.
$values = $form->getPhpValues();
$client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles());
@ste93cry Try my method ;)
+1 @sstok. That is the way to go in phpunit.
@sstok Is your workaround supposed to work in Symfony 2.3.x?
Ok, here's another workaround:
$form = $crawler->filter('form .submit-button .btn-primary')->form();
$formData = array(
'step2Type[positions][property1]' => '1',
'step2Type[positions][property2]' => 'xyz',
$this->client->request($form->getMethod(), $form->getUri(), $form->getPhpValues(), $form->getPhpFiles(), array(), http_build_query($formData))
I have field than as formed with the name like
And no workarounds works.
I can't change the field name has it's on a service I don't control...
This seems more like a mailinglist item than a bug/feature report afaics.
I've faced the same a few times now and ignored it ill now.. Still no solution there? The workarounds don't seem to work for me neither
Are property-paths, a property-path cannot be used for the DOMCrawler.
fnagel's solution works as it doesn't actually use the DOMCrawler but creates the request directly instead.
(moved to #3824 (comment))