Backend\Classes\FormField

Source: ~/modules/backend/classes/FormField.php

Form Field definition A translation of the form field configuration

Public properties

public string $fieldName

Form field name.

public string $arrayName

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

<input name="nameArray[fieldName]" />

public string $idPrefix

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

public string $label

Form field label.

public string $value

Form field value.

public string $valueFrom

Model attribute to use for the display value.

public string $defaults

Specifies a default value for supported fields.

public string $defaultFrom

Model attribute to use for the default value.

public string $tab

Specifies if this field belongs to a tab.

public string $type

Display mode. Text, textarea

public string $options

Field options.

public string $span

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

public string $size

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

public string $context

Specifies contextual visibility of this form field.

public bool $required

Specifies if this field is mandatory.

public bool $readOnly

Specify if the field is read-only or not.

public bool $disabled

Specify if the field is disabled or not.

public bool $hidden

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

public bool $stretch

Specifies if this field stretch to fit the page height.

public string $comment

Specifies a comment to accompany the field

public string $commentPosition

Specifies the comment position.

public string $commentHtml

Specifies if the comment is in HTML format.

public string $placeholder

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

public array $attributes

Contains a list of attributes specified in the field configuration.

public string $cssClass

Specifies a CSS class to attach to the field container.

public string $path

Specifies a path for partial-type fields.

public array $config

Raw field configuration.

public array $dependsOn

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

public array $trigger

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

public array $preset

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

Public methods

public void __construct(string $fieldName, string $label)

Constructor.

Parameters
  • string $fieldName - The name of the field
  • string $label - The label of the field

public void 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

public void 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'

public void displayAs(string $type, array $config=array())

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
  • string $type - Specifies a render mode as described above
  • array $config - A list of render mode specific config.

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

Returns the attributes for this field at a given position.

Parameters
  • string $position
  • $htmlBuild

public mixed getConfig(string $value, string $default=NULL)

Returns a raw config item value.

Parameters
  • string $value
  • string $default

public 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

public string getId(string $suffix=NULL)

Returns a value suitable for the field id property.

Parameters
  • string $suffix - Specify a suffix string

public string getName(string $arrayName=NULL)

Returns a value suitable for the field name property.

Parameters
  • string $arrayName - Specify a custom array name

public 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

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

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

Parameters
  • string $name
  • string $position

public bool isSelected(string $value=true)

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

Parameters
  • string $value

public self options(array $value=NULL)

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

Parameters
  • array $value

public array resolveModelAttribute(string $attribute, $attribute=NULL)

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

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

public void 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

public void span(string $value='full')

Sets a side of the field on a form.

Parameters
  • string $value - Specifies a side. Possible values: left, right, full

public void tab($value)

If this field belongs to a tab.

Parameters
  • $value

Protected methods

protected array evalConfig(array $config)

Process options and apply them to this object.

Parameters
  • array $config

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

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

Adds attributes used specifically by the Input Preset API

Parameters
  • array $attributes
  • string $position

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

Adds attributes used specifically by the Trigger API

Parameters
  • array $attributes
  • string $position

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