diff --git a/Form.php b/Form.php index fc2849e..20c16ec 100644 --- a/Form.php +++ b/Form.php @@ -418,14 +418,14 @@ private function initialize(): void // corresponding elements are either descendants or have a matching HTML5 form attribute $formId = Crawler::xpathLiteral($this->node->getAttribute('id')); - $fieldNodes = $xpath->query(sprintf('( descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)] )[not(ancestor::template)]', $formId)); + $fieldNodes = $xpath->query(sprintf('( descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)] )[( not(ancestor::template) or ancestor::turbo-stream )]', $formId)); foreach ($fieldNodes as $node) { $this->addField($node); } } else { // do the xpath query with $this->node as the context node, to only find descendant elements // however, descendant elements with form attribute are not part of this form - $fieldNodes = $xpath->query('( descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)] )[not(ancestor::template)]', $this->node); + $fieldNodes = $xpath->query('( descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)] )[( not(ancestor::template) or ancestor::turbo-stream )]', $this->node); foreach ($fieldNodes as $node) { $this->addField($node); } diff --git a/Tests/FormTest.php b/Tests/FormTest.php index 6804a87..fcbd216 100644 --- a/Tests/FormTest.php +++ b/Tests/FormTest.php @@ -432,6 +432,9 @@ public function testGetValues() $form = $this->createForm('
'); $this->assertEquals(['bar' => 'bar'], $form->getValues(), '->getValues() does not include template fields'); $this->assertFalse($form->has('foo')); + + $form = $this->createForm(''); + $this->assertEquals(['foo[bar]' => 'foo', 'bar' => 'bar', 'baz' => []], $form->getValues(), '->getValues() returns all form field values from template field inside a turbo-stream'); } public function testSetValues() @@ -486,6 +489,9 @@ public function testGetFiles() $form = $this->createForm('
'); $this->assertEquals([], $form->getFiles(), '->getFiles() does not include template file fields'); $this->assertFalse($form->has('foo')); + + $form = $this->createForm(''); + $this->assertEquals(['foo[bar]' => ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0]], $form->getFiles(), '->getFiles() return files fields from template inside turbo-stream'); } public function testGetPhpFiles()