FormField

Form Field definition A translation of the form field configuration

 class Backend\Classes\FormField

Constants

Constant Description
HIERARCHY_UP
string "^"

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

NO_SAVE_DATA
integer -1

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

Properties

public $arrayName : string

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

public $attributes : array

Contains a list of attributes specified in the field configuration.

public $comment : string

Specifies a comment to accompany the field

public $commentHtml : string

Specifies if the comment is in HTML format.

public $commentPosition : string

Specifies the comment position.

public $config : array

Raw field configuration.

public $context : string

Specifies contextual visibility of this form field.

public $cssClass : string

Specifies a CSS class to attach to the field container.

public $defaultFrom : string

Model attribute to use for the default value.

public $defaults : string

Specifies a default value for supported fields.

public $dependsOn : array

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

public $disabled : bool

Specify if the field is disabled or not.

public $fieldName : string

Form field name.

public $hidden : bool

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

public $idPrefix : string

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

public $label : string

Form field label.

public $options : string

Field options.

public $path : string

Specifies a path for partial-type fields.

public $placeholder : string

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

public $preset : array

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

public $readOnly : bool

Specify if the field is read-only or not.

public $required : bool

Specifies if this field is mandatory.

public $size : string

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

public $span : string

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

public $stretch : bool

Specifies if this field stretch to fit the page height.

public $tab : string

Specifies if this field belongs to a tab.

public $trigger : array

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

public $type : string

Display mode. Text, textarea

public $value : string

Form field value.

public $valueFrom : string

Model attribute to use for the display value.

Methods

public __construct (string $fieldName, string $label)

Constructor.

Parameters
Property Description
$fieldName
string

The name of the field

$label
string

The label of the field

Returns
mixed

public attributes (array $items, string $position = "field") : void

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
Property Description
$items
array
$position
string
Returns
void

public comment (string $text, string $position = "below", bool $isHtml = null)

Adds a text comment above or below the field.

Parameters
Property Description
$text
string

Specifies a comment text.

$position
string

Specifies a comment position.

$isHtml
bool

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

Returns
mixed

public 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.
  • 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
Property Description
$type
string

Specifies a render mode as described above

$config
array

A list of render mode specific config.

Returns
mixed

public getAttributes (string $position = "field", boolean $htmlBuild = true) : array

Returns the attributes for this field at a given position.

Parameters
Property Description
$position
string
$htmlBuild
boolean
Returns
array

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

Returns a raw config item value.

Parameters
Property Description
$value
string
$default
string
Returns
mixed

public getDefaultFromData (mixed $data) : mixed

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

Parameters
Property Description
$data
mixed
Returns
mixed

public getId (string $suffix = null) : string

Returns a value suitable for the field id property.

Parameters
Property Description
$suffix
string

Specify a suffix string

Returns
string

public getName (string $arrayName = null) : string

Returns a value suitable for the field name property.

Parameters
Property Description
$arrayName
string

Specify a custom array name

Returns
string

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

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

Parameters
Property Description
$data
mixed
$default
mixed
Returns
mixed

public hasAttribute (string $name, string $position = "field") : bool

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

Parameters
Property Description
$name
string
$position
string
Returns
bool

public isSelected (boolean $value = true) : bool

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

Parameters
Property Description
$value
boolean
Returns
bool

public options (array $value = null) : self

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

Parameters
Property Description
$value
array
Returns
self

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

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

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

Parameters
Property Description
$model
mixed
$attribute
string

.

Returns
array

public size (string $value = "large")

Sets a side of the field on a form.

Parameters
Property Description
$value
string

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

Returns
mixed

public span (string $value = "full")

Sets a side of the field on a form.

Parameters
Property Description
$value
string

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

Returns
mixed

public tab ($value)

If this field belongs to a tab.

Parameters
Property Description
$value
mixed
Returns
mixed

protected evalConfig (array $config) : array

Process options and apply them to this object.

Parameters
Property Description
$config
array
Returns
array

protected filterAttributes (array $attributes, string $position = "field") : array

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

Parameters
Property Description
$attributes
array
$position
string
Returns
array

protected filterPresetAttributes (array $attributes, string $position = "field") : array

Adds attributes used specifically by the Input Preset API

Parameters
Property Description
$attributes
array
$position
string
Returns
array

protected filterTriggerAttributes (array $attributes, string $position = "field") : array

Adds attributes used specifically by the Trigger API

Parameters
Property Description
$attributes
array
$position
string
Returns
array

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

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

Parameters
Property Description
$fieldName
string
$data
mixed
$default
mixed
Returns
mixed
Copyright © 2024 Winter CMS