public function testWithMultiDimensionalSource() { $choices = array("Non-vegetarian" => array(0 => 'Carnivore'), "Vegetarian" => array(3 => 'Carrots'), "Other" => array(9 => 'Vegan')); $f = new LookupField('test', 'test', $choices); $f->setValue(3); $this->assertEquals('<span class="readonly" id="test">Carrots</span><input type="hidden" name="test" value="3" />', $f->Field()->getValue()); $f->setValue(array(3, 9)); $this->assertEquals('<span class="readonly" id="test">Carrots, Vegan</span><input type="hidden" name="test" value="3, 9" />', $f->Field()->getValue()); }
function performReadonlyTransformation() { $field = new LookupField($this->name, $this->title, $this->source); $field->setValue($this->value); $field->setForm($this->form); return $field; }
function testArrayValueWithSqlMapSource() { $member1 = $this->objFromFixture('Member', 'member1'); $member2 = $this->objFromFixture('Member', 'member2'); $member3 = $this->objFromFixture('Member', 'member3'); $source = new SQLMap(singleton('Member')->buildSQL()); $f = new LookupField('test', 'test', $source); $f->setValue(array($member1->ID, $member2->ID)); $this->assertEquals(sprintf('<span class="readonly" id="test">member1, member2</span><input type="hidden" name="test" value="%s, %s" />', $member1->ID, $member2->ID), $f->Field()); }
public function testArrayValueWithSqlMapSource() { $member1 = $this->objFromFixture('Member', 'member1'); $member2 = $this->objFromFixture('Member', 'member2'); $member3 = $this->objFromFixture('Member', 'member3'); $source = DataObject::get('Member'); $f = new LookupField('test', 'test', $source->map()); $f->setValue(array($member1->ID, $member2->ID)); $this->assertEquals(sprintf('<span class="readonly" id="test">member1, member2</span>' . '<input type="hidden" name="test" value="%s, %s" />', $member1->ID, $member2->ID), $f->Field()); }
public function Field($properties = array()) { $fieldName = $this->labelField; if ($this->value) { $keyObj = $this->objectForKey($this->value); $obj = $keyObj ? $keyObj->{$fieldName} : ''; } else { $obj = null; } $source = array($this->value => $obj); $field = new LookupField($this->name, $this->title, $source); $field->setValue($this->value); $field->setForm($this->form); $field->dontEscape = true; return $field->Field(); }
function performReadonlyTransformation() { $fieldName = $this->labelField; $value = ($this->getByKey($this->value)) ? $this->getByKey($this->value)->$fieldName : ''; $source = array( $this->value => $value ); $field = new LookupField($this->name, $this->title, $source); $field->setValue($this->value); $field->setForm($this->form); $field->setReadonly(true); return $field; }
function performReadonlyTransformation() { $fieldName = $this->labelField; if ($this->value) { $obj = $this->getByKey($this->value) ? $this->getByKey($this->value)->{$fieldName} : ''; } else { $obj = null; } $source = array($this->value => $obj); $field = new LookupField($this->name, $this->title, $source); $field->setValue($this->value); $field->setForm($this->form); $field->setReadonly(true); return $field; }