class FormField

Form Field definition A translation of the form field configuration

Adapted from october\backend\classes\FormField

Constants

NO_SAVE_DATA

Properties

string $fieldName
string $arrayName
string $idPrefix
string $label
string $value
string $valueFrom
string $defaults
string $defaultFrom
string $tab
string $type
string $options
string $span
string $size
string $context
bool $required
bool $readOnly
bool $disabled
bool $hidden
bool $stretch
string $comment
string $commentPosition
string $commentHtml
string $placeholder
array $attributes
string $cssClass
string $path
array $config
array $dependsOn
array $trigger
array $preset

Methods

__construct(string $fieldName, string $label)

Constructor.

$this
tab($value)

If this field belongs to a tab.

$this
span(string $value = 'full')

Sets a side of the field on a form.

$this
size(string $value = 'large')

Sets a side of the field on a form.

FormField|array
options(array $value = null)

Sets field options, for dropdowns, radio lists and checkbox lists.

$this
displayAs(string $type, array $config = [])

Specifies a field control rendering mode. Supported modes are:

  • text - creates a text field. Default for varchar column types.

array
evalConfig(array $config)

Process options and apply them to this object.

$this
comment(string $text, string $position = 'below', bool $isHtml = null)

Adds a text comment above or below the field.

attributes(array $items, string $position = 'field')

Sets the attributes for this field in a given position.

bool
hasAttribute(string $name, string $position = 'field')

Checks if the field has the supplied [unfiltered] attribute.

string
getAttributes(string $position = 'field', bool $htmlBuild = true)

Returns the attributes for this field at a given position.

array
filterAttributes(array $attributes, string $position = 'field')

Adds any circumstantial attributes to the field based on other settings, such as the 'disabled' option.

array
filterTriggerAttributes(array $attributes, string $position = 'field')

Adds attributes used specifically by the Trigger API

array
filterPresetAttributes(array $attributes, string $position = 'field')

Adds attributes used specifically by the Input Preset API

string
getName(string $arrayName = null)

Returns a value suitable for the field name property.

string
getId(string $suffix = null)

Returns a value suitable for the field id property.

mixed
getConfig(string $value, string $default = null)

Returns a raw config item value.

mixed
getValueFromData(mixed $data, mixed $default = null)

Returns this fields value from a supplied data set, which can be an array or a model or another generic collection.

mixed
getDefaultFromData(mixed $data)

Returns the default value for this field, the supplied data is used to source data when defaultFrom is specified.

array
resolveModelAttribute($model, string $attribute = null)

Returns the final model and attribute name of a nested attribute.

mixed
getFieldNameFromData(string $fieldName, mixed $data, mixed $default = null)

Internal method to extract the value of a field name from a data set.

Details

at line 178
__construct(string $fieldName, string $label)

Constructor.

Parameters

string $fieldName
string $label

at line 191
$this tab($value)

If this field belongs to a tab.

Parameters

$value

Return Value

$this

at line 205
$this span(string $value = 'full')

Sets a side of the field on a form.

Parameters

string $value

Specifies a side. Possible values: left, right, full

Return Value

$this

at line 219
$this size(string $value = 'large')

Sets a side of the field on a form.

Parameters

string $value

Specifies a size. Possible values: tiny, small, large, huge, giant

Return Value

$this

at line 233
FormField|array options(array $value = null)

Sets field options, for dropdowns, radio lists and checkbox lists.

Parameters

array $value

Return Value

FormField|array

at line 269
$this displayAs(string $type, array $config = [])

Specifies a field control rendering mode. Supported modes are:

  • text - creates a text field. Default for varchar column types.

  • textarea - creates a textarea control. Default for text column types.
  • select - creates a drop-down list. Default for reference-based columns.
  • radio - creates a set of radio buttons.
  • checkbox - creates a single checkbox.
  • checkboxlist - creates a checkbox list.
  • radiolist - creates a radio list.

Parameters

string $type

Specifies a render mode as described above

array $config

A list of render mode specific config.

Return Value

$this

at line 284
protected array evalConfig(array $config)

Process options and apply them to this object.

Parameters

array $config

Return Value

array

at line 368
$this comment(string $text, string $position = 'below', bool $isHtml = null)

Adds a text comment above or below the field.

Parameters

string $text

Specifies a comment text.

string $position

Specifies a comment position.

bool $isHtml

Set to true if you use HTML formatting in the comment Supported values are 'below' and 'above'

Return Value

$this

at line 390
FormField attributes(array $items, string $position = 'field')

Sets the attributes for this field in a given position.

  • field: Attributes are added to the form field element (input, select, textarea, etc)
  • container: Attributes are added to the form field container (div.form-group)

Parameters

array $items
string $position

Return Value

FormField

at line 418
bool hasAttribute(string $name, string $position = 'field')

Checks if the field has the supplied [unfiltered] attribute.

Parameters

string $name
string $position

Return Value

bool

at line 436
string getAttributes(string $position = 'field', bool $htmlBuild = true)

Returns the attributes for this field at a given position.

Parameters

string $position
bool $htmlBuild

Return Value

string

at line 453
protected array filterAttributes(array $attributes, string $position = 'field')

Adds any circumstantial attributes to the field based on other settings, such as the 'disabled' option.

Parameters

array $attributes
string $position

Return Value

array

at line 483
protected array filterTriggerAttributes(array $attributes, string $position = 'field')

Adds attributes used specifically by the Trigger API

Parameters

array $attributes
string $position

Return Value

array

at line 530
protected array filterPresetAttributes(array $attributes, string $position = 'field')

Adds attributes used specifically by the Input Preset API

Parameters

array $attributes
string $position

Return Value

array

at line 572
string getName(string $arrayName = null)

Returns a value suitable for the field name property.

Parameters

string $arrayName

Specify a custom array name

Return Value

string

at line 593
string getId(string $suffix = null)

Returns a value suitable for the field id property.

Parameters

string $suffix

Specify a suffix string

Return Value

string

at line 621
mixed getConfig(string $value, string $default = null)

Returns a raw config item value.

Parameters

string $value
string $default

Return Value

mixed

at line 635
mixed getValueFromData(mixed $data, mixed $default = null)

Returns this fields value from a supplied data set, which can be an array or a model or another generic collection.

Parameters

mixed $data
mixed $default

Return Value

mixed

at line 650
mixed getDefaultFromData(mixed $data)

Returns the default value for this field, the supplied data is used to source data when defaultFrom is specified.

Parameters

mixed $data

Return Value

mixed

at line 672
array resolveModelAttribute($model, string $attribute = null)

Returns the final model and attribute name of a nested attribute.

Eg: list($model, $attribute) = $this->resolveAttribute('person[phone]');

Parameters

$model
string $attribute .

Return Value

array

at line 697
protected mixed getFieldNameFromData(string $fieldName, mixed $data, mixed $default = null)

Internal method to extract the value of a field name from a data set.

Parameters

string $fieldName
mixed $data
mixed $default

Return Value

mixed