FormField
Form Field definition
A translation of the form field configuration
class Backend\Classes\FormField
Constants
Constant | Type | Value | Description |
---|---|---|---|
HIERARCHY_UP
|
string |
"^"
|
string
"^"
A special character in yaml config files to indicate a field higher in hierarchy |
NO_SAVE_DATA
|
integer |
-1
|
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
= false
Specifies if the comment is in HTML format.
public
$commentPosition
:
string
= "below"
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
= false
Specify if the field is disabled or not.
public $fieldName : string
Form field name.
public
$hidden
:
bool
= false
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
= false
Specify if the field is read-only or not.
public $required : bool
Specifies if this field is mandatory.
public
$size
:
string
= "large"
Specifies a size. Possible values: tiny, small, large, huge, giant.
public
$span
:
string
= "full"
Specifies a side. Possible values: auto, left, right, full.
public
$stretch
:
bool
= false
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
= "text"
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.
Property | Type | Description |
---|---|---|
$fieldName | string |
string
The name of the field |
$label | string |
string
The label of the field |
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)
Property | Type | Description |
---|---|---|
$items | array |
array
|
$position | string |
string
|
public
comment (string $text, string $position = "below"
, bool $isHtml = null
)
Adds a text comment above or below the field.
Property | Type | Description |
---|---|---|
$text | string |
string
Specifies a comment text. |
$position | string |
string
Specifies a comment position. |
$isHtml | bool |
bool
Set to true if you use HTML formatting in the comment Supported values are 'below' and 'above' |
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.
Property | Type | Description |
---|---|---|
$type | string |
string
Specifies a render mode as described above |
$config | array |
array
A list of render mode specific config. |
public
getAttributes (string $position = "field"
, boolean $htmlBuild = true
)
: array
Returns the attributes for this field at a given position.
Property | Type | Description |
---|---|---|
$position | string |
string
|
$htmlBuild | boolean |
boolean
|
public
getConfig (string $value, string $default = null
)
: mixed
Returns a raw config item value.
Property | Type | Description |
---|---|---|
$value | string |
string
|
$default | string |
string
|
public getDefaultFromData (mixed $data) : mixed
Returns the default value for this field, the supplied data is used to source data when defaultFrom is specified.
Property | Type | Description |
---|---|---|
$data | mixed |
mixed
|
public
getId (string $suffix = null
)
: string
Returns a value suitable for the field id property.
Property | Type | Description |
---|---|---|
$suffix | string |
string
Specify a suffix string |
public
getName (string $arrayName = null
)
: string
Returns a value suitable for the field name property.
Property | Type | Description |
---|---|---|
$arrayName | string |
string
Specify a custom array name |
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.
Property | Type | Description |
---|---|---|
$data | mixed |
mixed
|
$default | mixed |
mixed
|
public
hasAttribute (string $name, string $position = "field"
)
: bool
Checks if the field has the supplied [unfiltered] attribute.
Property | Type | Description |
---|---|---|
$name | string |
string
|
$position | string |
string
|
public
isSelected (boolean $value = true
)
: bool
Determine if the provided value matches this field's value.
Property | Type | Description |
---|---|---|
$value | boolean |
boolean
|
public
options (array $value = null
)
: self
Sets field options, for dropdowns, radio lists and checkbox lists.
Property | Type | Description |
---|---|---|
$value | array |
array
|
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]');
Property | Type | Description |
---|---|---|
$model | mixed |
mixed
|
$attribute | string |
string
. |
public
size (string $value = "large"
)
Sets a side of the field on a form.
Property | Type | Description |
---|---|---|
$value | string |
string
Specifies a size. Possible values: tiny, small, large, huge, giant |
public
span (string $value = "full"
)
Sets a side of the field on a form.
Property | Type | Description |
---|---|---|
$value | string |
string
Specifies a side. Possible values: left, right, full |
public tab ($value)
If this field belongs to a tab.
Property | Type | Description |
---|---|---|
$value | mixed |
mixed
|
protected evalConfig (array $config) : array
Process options and apply them to this object.
Property | Type | Description |
---|---|---|
$config | array |
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.
Property | Type | Description |
---|---|---|
$attributes | array |
array
|
$position | string |
string
|
protected
filterPresetAttributes (array $attributes, string $position = "field"
)
: array
Adds attributes used specifically by the Input Preset API
Property | Type | Description |
---|---|---|
$attributes | array |
array
|
$position | string |
string
|
protected
filterTriggerAttributes (array $attributes, string $position = "field"
)
: array
Adds attributes used specifically by the Trigger API
Property | Type | Description |
---|---|---|
$attributes | array |
array
|
$position | string |
string
|
protected
getFieldNameFromData (string $fieldName, mixed $data, mixed $default = null
)
: mixed
Internal method to extract the value of a field name from a data set.
Property | Type | Description |
---|---|---|
$fieldName | string |
string
|
$data | mixed |
mixed
|
$default | mixed |
mixed
|