mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch 'fieldlist-fortemplate' of https://github.com/sminnee/sapphire
Conflicts: forms/FieldList.php
This commit is contained in:
commit
4e1c8bdb32
@ -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;
|
||||
}
|
||||
|
@ -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';
|
||||
}
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user