Documentation

FormField
in package

Form Field definition A translation of the form field configuration

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

HIERARCHY_UP  = '^'
NO_SAVE_DATA  = -1
$arrayName  : string
$attributes  : array<string|int, mixed>
$comment  : string
$commentHtml  : string
$commentPosition  : string
$config  : array<string|int, mixed>
$context  : string
$cssClass  : string
$defaultFrom  : string
$defaults  : string
$dependsOn  : array<string|int, mixed>
$disabled  : bool
$fieldName  : string
$hidden  : bool
$idPrefix  : string
$label  : string
$options  : string
$path  : string
$placeholder  : string
$preset  : array<string|int, mixed>
$readOnly  : bool
$required  : bool
$size  : string
$span  : string
$stretch  : bool
$tab  : string
$trigger  : array<string|int, mixed>
$type  : string
$value  : string
$valueFrom  : string
__construct()  : mixed
Constructor.
attributes()  : void
Sets the attributes for this field in a given position.
comment()  : mixed
Adds a text comment above or below the field.
displayAs()  : mixed
Specifies a field control rendering mode. Supported modes are: - text - creates a text field. Default for varchar column types.
getAttributes()  : array<string|int, mixed>
Returns the attributes for this field at a given position.
getConfig()  : mixed
Returns a raw config item value.
getDefaultFromData()  : mixed
Returns the default value for this field, the supplied data is used to source data when defaultFrom is specified.
getId()  : string
Returns a value suitable for the field id property.
getName()  : string
Returns a value suitable for the field name property.
getValueFromData()  : mixed
Returns this fields value from a supplied data set, which can be an array or a model or another generic collection.
hasAttribute()  : bool
Checks if the field has the supplied [unfiltered] attribute.
isSelected()  : bool
Determine if the provided value matches this field's value.
options()  : self
Sets field options, for dropdowns, radio lists and checkbox lists.
resolveModelAttribute()  : array<string|int, mixed>
Returns the final model and attribute name of a nested attribute. Eg:
size()  : mixed
Sets a side of the field on a form.
span()  : mixed
Sets a side of the field on a form.
tab()  : mixed
If this field belongs to a tab.
evalConfig()  : array<string|int, mixed>
Process options and apply them to this object.
filterAttributes()  : array<string|int, mixed>
Adds any circumstantial attributes to the field based on other settings, such as the 'disabled' option.
filterPresetAttributes()  : array<string|int, mixed>
Adds attributes used specifically by the Input Preset API
filterTriggerAttributes()  : array<string|int, mixed>
Adds attributes used specifically by the Trigger API
getFieldNameFromData()  : mixed
Internal method to extract the value of a field name from a data set.

Constants

HIERARCHY_UP

public string HIERARCHY_UP = '^'

A special character in yaml config files to indicate a field higher in hierarchy

NO_SAVE_DATA

public int NO_SAVE_DATA = -1

Value returned when the form field should not contribute any save data.

Properties

$arrayName

public string $arrayName

If the field element names should be contained in an array. Eg:

$attributes

public array<string|int, mixed> $attributes

Contains a list of attributes specified in the field configuration.

$comment

public string $comment

Specifies a comment to accompany the field

$commentHtml

public string $commentHtml = false

Specifies if the comment is in HTML format.

$commentPosition

public string $commentPosition = 'below'

Specifies the comment position.

$config

public array<string|int, mixed> $config

Raw field configuration.

$context

public string $context

Specifies contextual visibility of this form field.

$cssClass

public string $cssClass

Specifies a CSS class to attach to the field container.

$defaultFrom

public string $defaultFrom

Model attribute to use for the default value.

$defaults

public string $defaults

Specifies a default value for supported fields.

$dependsOn

public array<string|int, mixed> $dependsOn

Other field names this field depends on, when the other fields are modified, this field will update.

$disabled

public bool $disabled = false

Specify if the field is disabled or not.

$fieldName

public string $fieldName

Form field name.

$hidden

public bool $hidden = false

Specify if the field is hidden. Hiddens fields are not included in postbacks.

$idPrefix

public string $idPrefix

A prefix to the field identifier so it can be totally unique.

$label

public string $label

Form field label.

$options

public string $options

Field options.

$path

public string $path

Specifies a path for partial-type fields.

$placeholder

public string $placeholder

Specifies a message to display when there is no value supplied (placeholder).

$preset

public array<string|int, mixed> $preset

Other field names text is converted in to a URL, slug or file name value in this field.

$readOnly

public bool $readOnly = false

Specify if the field is read-only or not.

$required

public bool $required

Specifies if this field is mandatory.

$size

public string $size = 'large'

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

$span

public string $span = 'full'

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

$stretch

public bool $stretch = false

Specifies if this field stretch to fit the page height.

$tab

public string $tab

Specifies if this field belongs to a tab.

$trigger

public array<string|int, mixed> $trigger

Other field names this field can be triggered by, see the Trigger API documentation.

$type

public string $type = 'text'

Display mode. Text, textarea

$value

public string $value

Form field value.

$valueFrom

public string $valueFrom

Model attribute to use for the display value.

Methods

__construct()

Constructor.

public __construct(string $fieldName, string $label) : mixed
Parameters
$fieldName : string

The name of the field

$label : string

The label of the field

Return values
mixed

attributes()

Sets the attributes for this field in a given position.

public attributes(array<string|int, mixed> $items[, string $position = 'field' ]) : void
  • 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
$items : array<string|int, mixed>
$position : string = 'field'
Return values
void

comment()

Adds a text comment above or below the field.

public comment(string $text[, string $position = 'below' ][, bool $isHtml = null ]) : mixed
Parameters
$text : string

Specifies a comment text.

$position : string = 'below'

Specifies a comment position.

$isHtml : bool = null

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

Return values
mixed

displayAs()

Specifies a field control rendering mode. Supported modes are: - text - creates a text field. Default for varchar column types.

public displayAs(string $type[, array<string|int, mixed> $config = [] ]) : mixed
  • textarea - creates a textarea control. Default for text column types.
  • dropdown - 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.
  • switch - creates a switch field.
Parameters
$type : string

Specifies a render mode as described above

$config : array<string|int, mixed> = []

A list of render mode specific config.

Return values
mixed

getAttributes()

Returns the attributes for this field at a given position.

public getAttributes([string $position = 'field' ][, mixed $htmlBuild = true ]) : array<string|int, mixed>
Parameters
$position : string = 'field'
$htmlBuild : mixed = true
Return values
array<string|int, mixed>

getConfig()

Returns a raw config item value.

public getConfig(string $value[, string $default = null ]) : mixed
Parameters
$value : string
$default : string = null
Return values
mixed

getDefaultFromData()

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

public getDefaultFromData(mixed $data) : mixed
Parameters
$data : mixed
Return values
mixed

getId()

Returns a value suitable for the field id property.

public getId([string $suffix = null ]) : string
Parameters
$suffix : string = null

Specify a suffix string

Return values
string

getName()

Returns a value suitable for the field name property.

public getName([string $arrayName = null ]) : string
Parameters
$arrayName : string = null

Specify a custom array name

Return values
string

getValueFromData()

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

public getValueFromData(mixed $data[, mixed $default = null ]) : mixed
Parameters
$data : mixed
$default : mixed = null
Return values
mixed

hasAttribute()

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

public hasAttribute(string $name[, string $position = 'field' ]) : bool
Parameters
$name : string
$position : string = 'field'
Return values
bool

isSelected()

Determine if the provided value matches this field's value.

public isSelected([string $value = true ]) : bool
Parameters
$value : string = true
Return values
bool

options()

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

public options([array<string|int, mixed> $value = null ]) : self
Parameters
$value : array<string|int, mixed> = null
Return values
self

resolveModelAttribute()

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

public resolveModelAttribute(mixed $model[, mixed $attribute = null ]) : array<string|int, mixed>

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

Parameters
$model : mixed
$attribute : mixed = null
Return values
array<string|int, mixed>

size()

Sets a side of the field on a form.

public size([string $value = 'large' ]) : mixed
Parameters
$value : string = 'large'

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

Return values
mixed

span()

Sets a side of the field on a form.

public span([string $value = 'full' ]) : mixed
Parameters
$value : string = 'full'

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

Return values
mixed

tab()

If this field belongs to a tab.

public tab(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

evalConfig()

Process options and apply them to this object.

protected evalConfig(array<string|int, mixed> $config) : array<string|int, mixed>
Parameters
$config : array<string|int, mixed>
Return values
array<string|int, mixed>

filterAttributes()

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

protected filterAttributes(array<string|int, mixed> $attributes[, string $position = 'field' ]) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>
$position : string = 'field'
Return values
array<string|int, mixed>

filterPresetAttributes()

Adds attributes used specifically by the Input Preset API

protected filterPresetAttributes(array<string|int, mixed> $attributes[, string $position = 'field' ]) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>
$position : string = 'field'
Return values
array<string|int, mixed>

filterTriggerAttributes()

Adds attributes used specifically by the Trigger API

protected filterTriggerAttributes(array<string|int, mixed> $attributes[, string $position = 'field' ]) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>
$position : string = 'field'
Return values
array<string|int, mixed>

getFieldNameFromData()

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

protected getFieldNameFromData(string $fieldName, mixed $data[, mixed $default = null ]) : mixed
Parameters
$fieldName : string
$data : mixed
$default : mixed = null
Return values
mixed

Search results