Permalink
Browse files

Merge pull request #210 from sminnee/form-visiblefields

Form::VisibleFields() and FieldList::VisibleFields()
  • Loading branch information...
2 parents 2b24589 + 3d54668 commit 2ab12affece30e1acb2c704647b127510d11629c @stojg stojg committed Mar 9, 2012
Showing with 145 additions and 88 deletions.
  1. +24 −10 forms/FieldList.php
  2. +86 −78 forms/Form.php
  3. +35 −0 tests/forms/FieldListTest.php
View
@@ -219,7 +219,7 @@ public function replaceField($fieldName, $newField) {
* @param string $newFieldTitle New title of field
* @return boolean
*/
- function renameField($fieldName, $newFieldTitle) {
+ public function renameField($fieldName, $newFieldTitle) {
$field = $this->dataFieldByName($fieldName);
if(!$field) return false;
@@ -424,7 +424,7 @@ public function setValues($data) {
*
* @return FieldList
*/
- function HiddenFields() {
+ public function HiddenFields() {
$hiddenFields = new FieldList();
$dataFields = $this->dataFields();
@@ -434,14 +434,28 @@ function HiddenFields() {
return $hiddenFields;
}
+
+ /**
+ * Return all fields except for the hidden fields.
+ * Useful when making your own simplified form layouts.
+ */
+ public function VisibleFields() {
+ $visibleFields = new FieldList();
+
+ foreach($this as $field) {
+ if(!($field instanceof HiddenField)) $visibleFields->push($field);
+ }
+
+ return $visibleFields;
+ }
/**
* Transform this FieldList with a given tranform method,
* e.g. $this->transform(new ReadonlyTransformation())
*
* @return FieldList
*/
- function transform($trans) {
+ public function transform($trans) {
$this->flushFieldsCache();
$newFields = new FieldList();
foreach($this as $field) {
@@ -453,12 +467,12 @@ function transform($trans) {
/**
* Returns the root field set that this belongs to
*/
- function rootFieldSet() {
+ public function rootFieldSet() {
if($this->containerField) return $this->containerField->rootFieldSet();
else return $this;
}
- function setContainerField($field) {
+ public function setContainerField($field) {
$this->containerField = $field;
return $this;
}
@@ -468,7 +482,7 @@ function setContainerField($field) {
*
* @return FieldList
*/
- function makeReadonly() {
+ public function makeReadonly() {
return $this->transform(new ReadonlyTransformation());
}
@@ -477,7 +491,7 @@ function makeReadonly() {
*
* @param string|FormField
*/
- function makeFieldReadonly($field) {
+ public function makeFieldReadonly($field) {
$fieldName = ($field instanceof FormField) ? $field->getName() : $field;
$srcField = $this->dataFieldByName($fieldName);
$this->replaceField($fieldName, $srcField->performReadonlyTransformation());
@@ -492,7 +506,7 @@ function makeFieldReadonly($field) {
*
* @param array $fieldNames Field names can be given as an array, or just as a list of arguments.
*/
- function changeFieldOrder($fieldNames) {
+ public function changeFieldOrder($fieldNames) {
// Field names can be given as an array, or just as a list of arguments.
if(!is_array($fieldNames)) $fieldNames = func_get_args();
@@ -527,7 +541,7 @@ function changeFieldOrder($fieldNames) {
* @param string|FormField
* @return Position in children collection (first position starts with 0). Returns FALSE if the field can't be found.
*/
- function fieldPosition($field) {
+ public function fieldPosition($field) {
if(is_object($field)) $field = $field->getName();
$i = 0;
@@ -549,7 +563,7 @@ function fieldPosition($field) {
* @subpackage fields-structural
*/
class HiddenFieldList extends FieldList {
- function forTemplate() {
+ public function forTemplate() {
$output = "";
foreach($this as $field) {
$output .= $field->Field();
Oops, something went wrong.

0 comments on commit 2ab12af

Please sign in to comment.