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 5c17388

Browse filesBrowse files
author
Paweł Wacławczyk
committed
Allows using multiselect through Form::setValues().
1 parent f23fd03 commit 5c17388
Copy full SHA for 5c17388

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+11
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Form.php
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,14 @@ 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+
}
500+
else {
498501
$fields = self::create($name, $value);
499502
foreach ($fields->all() as $k => $v) {
500503
$this->set($k, $v);
501504
}
502-
} else {
503-
$target->setValue($value);
504505
}
505506
}
506507

‎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.