Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b6dfa76

Browse filesBrowse files
committed
merged branch pawaclawczyk/bugfix-multiselect-setvalues (PR #5502)
This PR was squashed before being merged into the 2.1 branch (closes #5502). Commits ------- 6200290 PSR-2 correct. 5c17388 Allows using multiselect through Form::setValues(). Discussion ---------- [DomCrawler] Allows using multiselect through Form::setValues(). Patch allows set multiple values in select using setValues() method, as it is used in Symfony\Component\BrowserKit\Client::submit().
2 parents 2fd699e + 74d10d6 commit b6dfa76
Copy full SHA for b6dfa76

File tree

Expand file treeCollapse file tree

2 files changed

+10
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-3
lines changed

‎src/Symfony/Component/DomCrawler/Form.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Form.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,13 @@ public function has($name)
494494
public function set($name, $value)
495495
{
496496
$target =& $this->get($name);
497-
if (is_array($value)) {
497+
if (!is_array($value) || $target instanceof Field\ChoiceFormField) {
498+
$target->setValue($value);
499+
} else {
498500
$fields = self::create($name, $value);
499501
foreach ($fields->all() as $k => $v) {
500502
$this->set($k, $v);
501503
}
502-
} else {
503-
$target->setValue($value);
504504
}
505505
}
506506

‎src/Symfony/Component/DomCrawler/Tests/FormTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Tests/FormTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ public function testSetValues()
273273
$this->assertEquals(array('bar' => 'foo'), $form->getValues(), '->setValues() sets the values of fields');
274274
}
275275

276+
public function testMultiselectSetValues()
277+
{
278+
$form = $this->createForm('<form><select multiple="multiple" name="multi"><option value="foo">foo</option><option value="bar">bar</option></select><input type="submit" /></form>');
279+
$form->setValues(array('multi' => array("foo", "bar")));
280+
$this->assertEquals(array('multi' => array('foo', 'bar')), $form->getValues(), '->setValue() sets tehe values of select');
281+
}
282+
276283
public function testGetPhpValues()
277284
{
278285
$form = $this->createForm('<form><input type="text" name="foo[bar]" value="foo" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.