public function setValue($val, $obj = null) { if (!$val && $obj && $obj instanceof DataObject && $obj->hasMethod($this->name)) { $funcName = $this->name; if ($this->tags) { $val = array(); foreach ($obj->{$funcName}() as $o) { $val[] = $o->Title; } } else { $val = array_values($obj->{$funcName}()->getIDList()); } } if ($val && !is_array($val)) { $val = explode(self::SEPARATOR, $val); } return parent::setValue($val, $obj); }
public function testFieldRenderingMultipleOn() { $choices = array('a' => 'a value', 'b' => 'b value', 'c' => 'c value'); $field = new ListboxField('Choices', 'Choices', $choices); $field->multiple = true; $field->setValue('a,c'); $parser = new CSSContentParser($field->Field()); $optEls = $parser->getBySelector('option'); $this->assertEquals(3, count($optEls)); $this->assertEquals('selected', (string) $optEls[0]['selected']); $this->assertEquals('', (string) $optEls[1]['selected']); $this->assertEquals('selected', (string) $optEls[2]['selected']); }