API: LookupField::Field now returns an HTMLText instance.

Moved LookupField into a template, removed getSource() as the DropdownField getSource() has been simplified to just a getter
This commit is contained in:
Will Rossiter 2013-10-18 10:28:17 +13:00
parent 8c527eab40
commit 1c983bc16d
3 changed files with 16 additions and 20 deletions

View File

@ -71,9 +71,12 @@ class LookupField extends DropdownField {
$inputValue = '';
}
return "<span class=\"readonly\" id=\"" . $this->id() .
"\">$attrValue</span><input type=\"hidden\" name=\"" . $this->name .
"\" value=\"" . $inputValue . "\" />";
$properties = array_merge($properties, array(
'AttrValue' => $attrValue,
'InputValue' => $inputValue
));
return parent::Field($properties);
}
/**
@ -91,14 +94,5 @@ class LookupField extends DropdownField {
public function Type() {
return "lookup readonly";
}
/**
* Override parent behavior by not merging arrays.
*
* @return array
*/
public function getSource() {
return $this->source;
}
}

View File

@ -0,0 +1 @@
<span class="readonly" id="$ID">$AttrValue</span><input type="hidden" name="$Name" value="$InputValue" />

View File

@ -13,9 +13,10 @@ class LookupFieldTest extends SapphireTest {
$source = array(1 => 'one', 2 => 'two', 3 => 'three');
$f = new LookupField('test', 'test', $source);
$f->setValue(null);
$this->assertEquals(
'<span class="readonly" id="test"><i>(none)</i></span><input type="hidden" name="test" value="" />',
$f->Field()
$f->Field()->getValue()
);
}
@ -25,7 +26,7 @@ class LookupFieldTest extends SapphireTest {
$f->setValue(1);
$this->assertEquals(
'<span class="readonly" id="test">one</span><input type="hidden" name="test" value="1" />',
$f->Field()
$f->Field()->getValue()
);
}
@ -36,7 +37,7 @@ class LookupFieldTest extends SapphireTest {
$f->dontEscape = true; // simulates CMSMain->compareversions()
$this->assertEquals(
'<span class="readonly" id="test"><ins>w00t</ins></span><input type="hidden" name="test" value="" />',
$f->Field()
$f->Field()->getValue()
);
}
@ -47,7 +48,7 @@ class LookupFieldTest extends SapphireTest {
$f->setValue(array('one','two'));
$this->assertEquals('<span class="readonly" id="test">one val, two val</span>'
. '<input type="hidden" name="test" value="one, two" />',
$f->Field()
$f->Field()->getValue()
);
}
@ -58,7 +59,7 @@ class LookupFieldTest extends SapphireTest {
$f->setValue(array(1,2));
$this->assertEquals(
'<span class="readonly" id="test">one, two</span><input type="hidden" name="test" value="1, 2" />',
$f->Field()
$f->Field()->getValue()
);
}
@ -78,7 +79,7 @@ class LookupFieldTest extends SapphireTest {
$member1->ID,
$member2->ID
),
$f->Field()
$f->Field()->getValue()
);
}
@ -100,7 +101,7 @@ class LookupFieldTest extends SapphireTest {
$this->assertEquals(
'<span class="readonly" id="test">Carrots</span><input type="hidden" name="test" value="3" />',
$f->Field()
$f->Field()->getValue()
);
$f->setValue(array(
@ -109,7 +110,7 @@ class LookupFieldTest extends SapphireTest {
$this->assertEquals(
'<span class="readonly" id="test">Carrots, Vegan</span><input type="hidden" name="test" value="3, 9" />',
$f->Field()
$f->Field()->getValue()
);
}
}