Merge branch 'fieldlist-fortemplate' of https://github.com/sminnee/sapphire

Conflicts:
	forms/FieldList.php
This commit is contained in:
Ingo Schommer 2012-03-09 17:03:02 +01:00
commit 4e1c8bdb32
3 changed files with 35 additions and 12 deletions

View File

@ -553,20 +553,13 @@ class FieldList extends ArrayList {
return false;
}
}
/**
* A field list designed to store a list of hidden fields. When inserted into a template, only the
* input tags will be included
*
* @package forms
* @subpackage fields-structural
/**
* Default template rendering of a FieldList will concatenate all FieldHolder values.
*/
class HiddenFieldList extends FieldList {
public function forTemplate() {
function forTemplate() {
$output = "";
foreach($this as $field) {
$output .= $field->Field();
$output .= $field->FieldHolder();
}
return $output;
}

View File

@ -74,6 +74,10 @@ class FormAction extends FormField {
return $this->customise($properties)->renderWith($this->getTemplate());
}
function FieldHolder() {
return $this->Field();
}
public function Type() {
return 'action';
}

View File

@ -715,6 +715,32 @@ class FieldListTest extends SapphireTest {
unset($set);
}
/**
* FieldList::forTemplate() returns a concatenation of FieldHolder values.
*/
function testForTemplate() {
$set = new FieldList(
$a = new TextField('A'),
$b = new TextField('B')
);
$this->assertEquals($a->FieldHolder() . $b->FieldHolder(), $set->forTemplate());
}
/**
* FieldList::forTemplate() for an action list returns a concatenation of Field values.
* Internally, this works by having FormAction::FieldHolder return just the field, but it's an important
* use-case to test.
*/
function testForTemplateForActionList() {
$set = new FieldList(
$a = new FormAction('A'),
$b = new FormAction('B')
);
$this->assertEquals($a->Field() . $b->Field(), $set->forTemplate());
}
function testMakeFieldReadonly() {
$FieldList = new FieldList(
new TabSet('Root', new Tab('Main',