Version: current

# Class FieldSet

DataObjectSet designed for form fields. It extends the DataObjectSet with the ability to get a sequential set of fields.

  Object
  ViewableData implements IteratorAggregate
  DataObjectSet implements IteratorAggregate, Countable
  FieldSet

### Direct known subclasses

`HiddenFieldSet`

Package: forms\fields-structural
Located at sapphire/forms/FieldSet.php

## Methods summary

`public` | # `__construct( `ViewableData`|array|mixed $items = null )` Create a new DataObjectSet. If you pass one or more arguments, it will try to convert them into `ArrayData` objects. Create a new DataObjectSet. If you pass one or more arguments, it will try to convert them into `ArrayData` objects. #### Parameters $items ViewableData|array|mixed $items Parameters to use in this set, either as an associative array, object with simple properties, or as multiple parameters. #### Overrides `DataObjectSet::__construct`
`public` | # `dataFields( )` Return a sequential set of all fields that have data. This excludes wrapper composite fields as well as heading / help text fields. Return a sequential set of all fields that have data. This excludes wrapper composite fields as well as heading / help text fields. #### Used by ``Form::loadDataFrom()``
`public` | # `saveableFields( )`
`protected` | # `flushFieldsCache( )`
`protected` | # `collateDataFields( mixed & $list, mixed $saveableOnly = false )` #### Used by ``FieldSet::$sequentialSet``
`public` | # `addFieldToTab( string $tabName, `FormField` $field, string $insertBefore = null )` Add an extra field to a tab within this fieldset. This is most commonly used when overloading getCMSFields() Add an extra field to a tab within this fieldset. This is most commonly used when overloading getCMSFields() #### Parameters $tabName string $tabName The name of the tab or tabset. Subtabs can be referred to as TabSet.Tab or TabSet.Tab.Subtab. This function will create any missing tabs. $field FormField $field The `FormField` object to add to the end of that tab. $insertBefore string $insertBefore The name of the field to insert before. Optional.
`public` | # `addFieldsToTab( string $tabName, array $fields )` Add a number of extra fields to a tab within this fieldset. This is most commonly used when overloading getCMSFields() Add a number of extra fields to a tab within this fieldset. This is most commonly used when overloading getCMSFields() #### Parameters $tabName string $tabName The name of the tab or tabset. Subtabs can be referred to as TabSet.Tab or TabSet.Tab.Subtab. This function will create any missing tabs. $fields array $fields An array of `FormField` objects.
`public` | # `removeFieldFromTab( string $tabName, string $fieldName )` Remove the given field from the given tab in the field. Remove the given field from the given tab in the field. #### Parameters $tabName string $tabName The name of the tab $fieldName string $fieldName The name of the field
`public` | # `removeFieldsFromTab( string $tabName, array $fields )` Removes a number of fields from a Tab/TabSet within this FieldSet. Removes a number of fields from a Tab/TabSet within this FieldSet. #### Parameters $tabName string $tabName The name of the Tab or TabSet field $fields array $fields A list of fields, e.g. array('Name', 'Email')
`public` | # `removeByName( string $fieldName, boolean $dataFieldOnly = false )` Remove a field from this FieldSet by Name. The field could also be inside a CompositeField. Remove a field from this FieldSet by Name. The field could also be inside a CompositeField. #### Parameters $fieldName string $fieldName The name of the field or tab $dataFieldOnly boolean $dataFieldOnly If this is true, then a field will only be removed if it's a data field. Dataless fields, such as tabs, will be left as-is.
`public boolean` | # `replaceField( string $fieldName, `FormField` $newField )` Replace a single field with another. Ignores dataless fields such as Tabs and TabSets Replace a single field with another. Ignores dataless fields such as Tabs and TabSets #### Parameters $fieldName string $fieldName The name of the field to replace $newField FormField $newField The field object to replace with #### Returns `boolean` TRUE field was successfully replaced FALSE field wasn't found, nothing changed
`public boolean` | # `renameField( string $fieldName, string $newFieldTitle )` Rename the title of a particular field name in this set. Rename the title of a particular field name in this set. #### Parameters $fieldName string $fieldName Name of field to rename title of $newFieldTitle string $newFieldTitle New title of field #### Returns `boolean` boolean
`public boolean` | # `hasTabSet( )` #### Returns `boolean` boolean
`public `Tab`` | # `findOrMakeTab( string $tabName, string $title = null )` Returns the specified tab object, creating it if necessary. Returns the specified tab object, creating it if necessary. #### Parameters $tabName string $tabName The tab to return, in the form "Tab.Subtab.Subsubtab". Caution: Does not recursively create TabSet instances, you need to make sure everything up until the last tab in the chain exists. $title string $title Natural language title of the tab. If $tabName is passed in dot notation, the title parameter will only apply to the innermost referenced tab. The title is only changed if the tab doesn't exist already. #### Returns ``Tab`` The found or newly created Tab instance
`public` | # `fieldByName( mixed $name )` Returns a named field. You can use dot syntax to get fields from child composite fields Returns a named field. You can use dot syntax to get fields from child composite fields
`public `FormField`` | # `dataFieldByName( string $name )` Returns a named field in a sequential set. Use this if you're using nested FormFields. Returns a named field in a sequential set. Use this if you're using nested FormFields. #### Parameters $name string $name The name of the field to return #### Returns ``FormField`` instance
`public` | # `insertBefore( `FormField` $item, string $name )` Inserts a field before a particular field in a FieldSet. Inserts a field before a particular field in a FieldSet. #### Parameters $item FormField $item The form field to insert $name string $name Name of the field to insert before #### Used by ``CompositeField::insertBefore()``
`public` | # `insertAfter( `FormField` $item, string $name )` Inserts a field after a particular field in a FieldSet. Inserts a field after a particular field in a FieldSet. #### Parameters $item FormField $item The form field to insert $name string $name Name of the field to insert after
`public` | # `push( `FormField` $item, string $key = null )` Push a single field into this FieldSet instance. Push a single field into this FieldSet instance. #### Parameters $item FormField $item The FormField to add $key string $key An option array key (field name) #### Overrides `DataObjectSet::push`
`protected` | # `onBeforeInsert( mixed $item )` Handler method called before the FieldSet is going to be manipulated. Handler method called before the FieldSet is going to be manipulated.
`public` | # `setForm( `Form` $form )` Set the Form instance for this FieldSet. Set the Form instance for this FieldSet. #### Parameters $form Form $form The form to set this FieldSet to
`public` | # `setValues( data $data )` Load the given data into this form. Load the given data into this form. #### Parameters $data data An map of data to load into the FieldSet
`public `FieldSet`` | # `HiddenFields( )` Return all <input type="hidden"> fields in a form - including fields nested in CompositeFields. Useful when doing custom field layouts. Return all <input type="hidden"> fields in a form - including fields nested in CompositeFields. Useful when doing custom field layouts. #### Returns ``FieldSet`` FieldSet
`public `FieldSet`` | # `transform( mixed $trans )` Transform this FieldSet with a given tranform method, e.g. $this->transform(new ReadonlyTransformation()) Transform this FieldSet with a given tranform method, e.g. $this->transform(new ReadonlyTransformation()) #### Returns ``FieldSet`` FieldSet
`public` | # `rootFieldSet( )` Returns the root field set that this belongs to Returns the root field set that this belongs to
`public` | # `setContainerField( mixed $field )`
`public `FieldSet`` | # `makeReadonly( )` Transforms this FieldSet instance to readonly. Transforms this FieldSet instance to readonly. #### Returns ``FieldSet`` FieldSet
`public` | # `makeFieldReadonly( string|`FormField` $field )` Transform the named field into a readonly feld. Transform the named field into a readonly feld. #### Parameters $field string|FormField
`public` | # `changeFieldOrder( array $fieldNames )` Change the order of fields in this FieldSet by specifying an ordered list of field names. This works well in conjunction with SilverStripe's scaffolding functions: take the scaffold, and shuffle the fields around to the order that you want. Change the order of fields in this FieldSet by specifying an ordered list of field names. This works well in conjunction with SilverStripe's scaffolding functions: take the scaffold, and shuffle the fields around to the order that you want. Please note that any tabs or other dataless fields will be clobbered by this operation. #### Parameters $fieldNames array $fieldNames Field names can be given as an array, or just as a list of arguments.
`public Position` | # `fieldPosition( string|`FormField` $field )` Find the numerical position of a field within the children collection. Doesn't work recursively. Find the numerical position of a field within the children collection. Doesn't work recursively. #### Parameters $field string|FormField #### Returns `Position` in children collection (first position starts with 0). Returns FALSE if the field can't be found.

### Methods inherited from DataObjectSet

`Count()`, `CurrentPage()`, `First()`, `FirstItem()`, `GroupedBy()`, `Last()`, `LastItem()`, `MoreThanOnePage()`, `NextLink()`, `NotFirstPage()`, `NotLastPage()`, `Pages()`, `PaginationSummary()`, `PrevLink()`, `TotalItems()`, `TotalPages()`, `UL()`, `addWithoutWrite()`, `buildNestedUL()`, `column()`, `containsIDs()`, `debug()`, `destroy()`, `emptyItems()`, `exists()`, `find()`, `forTemplate()`, `getChildrenAsUL()`, `getIterator()`, `getPageLimits()`, `getRange()`, `groupBy()`, `groupWithParents()`, `hasValue()`, `insertFirst()`, `map()`, `merge()`, `onlyContainsIDs()`, `parseQueryLimit()`, `pop()`, `remove()`, `removeDuplicates()`, `replace()`, `setPageLength()`, `setPageLimits()`, `setPaginationGetVar()`, `shift()`, `sort()`, `toArray()`, `toDropDownMap()`, `toNestedArray()`, `unshift()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `Debug()`, `Even()`, `EvenOdd()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Methods inherited from Countable

`count()`

### Magic methods summary

## Properties summary

`protected array` | $sequentialSet | # Cached flat representation of all fields in this set, including fields nested in CompositeFields. Cached flat representation of all fields in this set, including fields nested in CompositeFields. #### Uses ``FieldSet::collateDataFields()``
`protected array` | $sequentialSaveableSet | #
`protected mixed` | $containerField | #

### Properties inherited from DataObjectSet

`$current`, `$first`, `$items`, `$last`, `$odd`, `$pageLength`, `$pageStart`, `$paginationGetVar`, `$totalSize`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -