Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [VarExporter] Uniform unitialized property error message under ghost and non-ghost objects
  [AssetMapper] Ignore comment lines in JavaScriptImportPathCompiler
  Update configuration path in help message
  [Validator] Review Albanian translation
  [Process] Fix Inconsistent Exit Status in proc_get_status for PHP Versions Below 8.3
  [Validator] Update Czech (cz) translation
  Sync translations
  [Mailer][Postmark][Webhook] Make allowed IPs configurable
  Review portuguese translations
  [Validator] Fix fields without constraints in `Collection`
  deal with fields for which no constraints have been configured
  [DomCrawler] [Form] Fix the exclusion of <template>
  • Loading branch information
derrabus committed Feb 12, 2024
2 parents 3330a8f + f0e7ec3 commit 6cb272c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ public function testGetValues()
$form = $this->createForm('<form><template><input type="text" name="foo" value="foo" /></template><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$this->assertEquals(['bar' => 'bar'], $form->getValues(), '->getValues() does not include template fields');
$this->assertFalse($form->has('foo'));

$form = $this->createForm('<turbo-stream><template><form><input type="text" name="foo[bar]" value="foo" /><input type="text" name="bar" value="bar" /><select multiple="multiple" name="baz[]"></select><input type="submit" /></form></template></turbo-stream>');
$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()
Expand Down Expand Up @@ -486,6 +489,9 @@ public function testGetFiles()
$form = $this->createForm('<form method="post"><template><input type="file" name="foo"/></template><input type="text" name="bar" value="bar"/><input type="submit"/></form>');
$this->assertEquals([], $form->getFiles(), '->getFiles() does not include template file fields');
$this->assertFalse($form->has('foo'));

$form = $this->createForm('<turbo-stream><template><form method="post"><input type="file" name="foo[bar]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form></template></turbo-stream>');
$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()
Expand Down

0 comments on commit 6cb272c

Please sign in to comment.