HumHub Documentation (unofficial)

ActiveField extends ActiveField
in package

Extends the ActiveField component to handle various bootstrap form types and handle input groups.

Example(s):

   echo $this->form->field($model, 'email', ['addon' => ['type'=>'prepend', 'content'=>'@']]);
   echo $this->form->field($model, 'amount_paid', ['addon' => ['type'=>'append', 'content'=>'.00']]);
   echo $this->form->field($model, 'phone', ['addon' => ['type'=>'prepend', 'content'=>'<i class="glyphicon
    glyphicon-phone']]);
Tags
author

Kartik Visweswaran kartikv2@gmail.com

since
1.0

Table of Contents

Constants

HINT_DEFAULT  = 1
HINT_SPECIAL  = 2
MULTI_SELECT_HEIGHT  = '145px'
NOT_SET  = ''
TYPE_CHECKBOX  = 'checkbox'
TYPE_RADIO  = 'radio'

Properties

$addAriaAttributes  : bool
$addClass  : string
$addon  : array<string|int, mixed>
$attribute  : string
$autoOffset  : bool
$autoPlaceholder  : bool
$behaviors  : array<string|int, Behavior>
$checkEnclosedTemplate  : string
$checkTemplate  : string
$checkWrapperOptions  : array<string|int, mixed>
$contentAfterError  : string
$contentAfterField  : string
$contentAfterHint  : string
$contentAfterInput  : string
$contentAfterLabel  : string
$contentBeforeError  : string
$contentBeforeField  : string
$contentBeforeHint  : string
$contentBeforeInput  : string
$contentBeforeLabel  : string
$customFileTemplate  : string
$deviceSize  : string
$enableAjaxValidation  : bool|null
$enableClientValidation  : bool|null
$enableError  : bool
$enableLabel  : bool
$errorOptions  : array<string|int, mixed>
$feedbackIcon  : array<string|int, mixed>
$form  : ActiveForm
$form  : ActiveForm
$form  : ActiveForm
$highlightAddon  : bool
$hintOptions  : array<string|int, mixed>
$hintSettings  : array<string|int, mixed>
$hintType  : int
$horizontalCssClasses  : null|array<string|int, mixed>
$inputOptions  : array<string|int, mixed>
$labelOptions  : array<string|int, mixed>
$labelSpan  : int
$model  : Model
$options  : array<string|int, mixed>
$parts  : array<string|int, mixed>
$renderEmptyWrapper  : bool
$selectors  : array<string|int, mixed>
$showErrors  : bool
$showHints  : bool
$showLabels  : bool|string
$showRequiredIndicator  : bool
$skipFormLayout  : bool
$staticValue  : string
$template  : string
$validateOnBlur  : bool|null
$validateOnChange  : bool|null
$validateOnType  : bool|null
$validationDelay  : int|null
$wrapperOptions  : array<string|int, mixed>
$_hasFeedback  : bool
$_isHintSpecial  : bool
$_isStatic  : bool
$_multiselect  : bool
$_offset  : bool
$_pluginHintKeys  : array<string|int, mixed>
$_settings  : array<string|int, mixed>
$_behaviors  : array<string|int, Behavior>|null
$_events  : array<string|int, mixed>
$_eventWildcards  : array<string|int, mixed>
$_hintPopoverContainer  : string
$_iconBesideInput  : bool
$_inputCss  : string
$_inputId  : string
$_labelCss  : string
$_skipLabelFor  : bool

Methods

__call()  : mixed
Calls the named method which is not a class method.
__clone()  : mixed
This method is called after the object is created by cloning an existing one.
__construct()  : mixed
Constructor.
__get()  : mixed
Returns the value of a component property.
__isset()  : bool
Checks if a property is set, i.e. defined and not null.
__set()  : mixed
Sets the value of a component property.
__toString()  : string
PHP magic method that returns the string representation of this object.
__unset()  : mixed
Sets a component property to be null.
attachBehavior()  : Behavior
Attaches a behavior to this component.
attachBehaviors()  : mixed
Attaches a list of behaviors to the component.
begin()  : string
Renders the opening tag of the field container.
behaviors()  : array<string|int, mixed>
Returns a list of behaviors that this component should behave as.
canGetProperty()  : bool
Returns a value indicating whether a property can be read.
canSetProperty()  : bool
Returns a value indicating whether a property can be set.
checkbox()  : ActiveField
Renders a checkbox. This method will generate the "checked" tag attribute according to the model attribute value.
checkboxButtonGroup()  : ActiveField
Renders a list of checkbox toggle buttons.
checkboxList()  : ActiveField
Renders a list of checkboxes. A checkbox list allows multiple selection, like [[listBox()]]. As a result, the corresponding submitted value is an array. The selection of the checkbox list is taken from the value of the model attribute.
className()  : string
Returns the fully qualified name of this class.
detachBehavior()  : Behavior|null
Detaches a behavior from the component.
detachBehaviors()  : mixed
Detaches all behaviors from the component.
dropDownList()  : $this
Renders a drop-down list.
end()  : string
Renders the closing tag of the field container.
ensureBehaviors()  : mixed
Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
error()  : $this
Generates a tag that contains the first validation error of [[attribute]].
fileInput()  : $this
Renders a file input.
getBehavior()  : Behavior|null
Returns the named behavior object.
getBehaviors()  : array<string|int, Behavior>
Returns all behaviors attached to this component.
hasEventHandlers()  : bool
Returns a value indicating whether there is any handler attached to the named event.
hasMethod()  : bool
Returns a value indicating whether a method is defined.
hasProperty()  : bool
Returns a value indicating whether a property is defined for this component.
hiddenInput()  : $this
Renders a hidden input.
hint()  : $this
Renders the hint tag.
init()  : mixed
Initializes the object.
input()  : $this
Renders an input tag.
label()  : $this
Generates a label tag for [[attribute]].
listBox()  : $this
Renders a list box.
multiselect()  : ActiveField
Renders a multi select list box. This control extends the checkboxList and radioList available in [[YiiActiveField]] - to display a scrolling multi select list box.
off()  : bool
Detaches an existing event handler from this component.
on()  : mixed
Attaches an event handler to an event.
passwordInput()  : $this
Renders a password input.
radio()  : ActiveField
Renders a radio button. This method will generate the "checked" tag attribute according to the model attribute value.
radioButtonGroup()  : ActiveField
Renders a list of radio toggle buttons.
radioList()  : ActiveField
Renders a list of radio buttons. A radio button list is like a checkbox list, except that it only allows single selection. The selection of the radio buttons is taken from the value of the model attribute.
render()  : string
Renders the whole field.
staticInput()  : ActiveField
Renders a static input (display only).
textarea()  : $this
Renders a text area.
textInput()  : $this
Renders a text input.
trigger()  : mixed
Triggers an event.
widget()  : $this
Renders a widget as the input of the field.
addAriaAttributes()  : mixed
Adds aria attributes to the input options.
addErrorClassBS4()  : mixed
Adds Bootstrap 4 validation class to the input options if needed.
addErrorClassIfNeeded()  : mixed
Adds validation class to the input options if needed.
addRoleAttributes()  : mixed
Add role attributes to the input options
adjustLabelFor()  : mixed
Adjusts the `for` attribute for the label based on the input options.
buildLayoutParts()  : mixed
Builds the field layout parts
buildTemplate()  : mixed
Builds the final template based on the bootstrap form type, display settings for label, error, and hint, and content before and after label, input, error, and hint.
createLayoutConfig()  : array<string|int, mixed>
Create layout specific configuration
generateAddon()  : string
Generates the addon markup
generateHint()  : string
Generates the hint.
getAddonContent()  : string
Parses and returns addon content.
getClientOptions()  : array<string|int, mixed>
Returns the JS options for the field.
getColCss()  : string
Gets bootstrap grid column CSS based on size
getConfigParam()  : string|bool
Gets configuration parameter from formConfig
getCustomCss()  : string
Gets custom CSS for custom controls supported in bootstrap 4.x and 5.x
getFeedbackIcon()  : string
Generates a feedback icon
getHintData()  : mixed
Gets a hint configuration setting value
getHintIcon()  : string
Generates the hint icon
getHintIconCss()  : array<string|int, mixed>
Gets the hint icon css based on `hintSettings`
getInputId()  : string
Returns the HTML `id` of the input element of this form field.
getToggleField()  : ActiveField
Generates a toggle field (checkbox or radio)
getToggleFieldList()  : ActiveField
Renders a list of checkboxes / radio buttons. The selection of the checkbox / radio buttons is taken from the value of the model attribute.
hasLabels()  : bool|string
Validate label display status
initActiveField()  : mixed
Initialize the active field
initDisability()  : mixed
Validates and sets disabled or readonly inputs
initFieldOptions()  : mixed
Initializes sizes and placeholder based on $autoPlaceholder
initFieldSize()  : mixed
Initializes field by detecting the bootstrap CSS size and sets a size modifier CSS to the field container
initHints()  : mixed
Initialize hint settings
initHorizontal()  : mixed
Prepares bootstrap grid col classes for horizontal layout including label and input tags and initiate private CSS variables. The process order for 'labelSpan' and 'wrapper' is as follows:
initLabels()  : mixed
Initialize label options
initLayout()  : mixed
Initialize layout settings for label, input, error and hint blocks and for various bootstrap 3 form layouts
isAjaxValidationEnabled()  : bool
Checks if ajax validation enabled for the field.
isClientValidationEnabled()  : bool
Checks if client validation enabled for the field.
isCustomControl()  : bool
Checks whether bootstrap 4.x custom control based on `options` parameter
mergeSettings()  : mixed
Merges the parameters for layout settings
parseFormFlag()  : void
Parses the form flag (for disabled/readonly).
renderAddonItem()  : string
Renders an addon item based on its configuration
renderFeedbackIcon()  : string
Render the bootstrap feedback icon
renderLabelParts()  : mixed
Render the label parts
setHintData()  : mixed
Sets a hint property setting as a data attribute within `self::$options`
setLayoutContainer()  : mixed
Sets the layout element container
attachBehaviorInternal()  : Behavior
Attaches a behavior to this component.

Constants

HINT_DEFAULT

public string HINT_DEFAULT = 1

default hint type that is displayed below the input

HINT_SPECIAL

public string HINT_SPECIAL = 2

special hint type that allows display via an indicator icon or on hover/click of the field label

MULTI_SELECT_HEIGHT

public string MULTI_SELECT_HEIGHT = '145px'

the default height for the Krajee multi select input

NOT_SET

public string NOT_SET = ''

an empty string value

TYPE_CHECKBOX

public string TYPE_CHECKBOX = 'checkbox'

HTML checkbox input type

TYPE_RADIO

public string TYPE_RADIO = 'radio'

HTML radio input type

Properties

$addAriaAttributes

public bool $addAriaAttributes = true

adds aria HTML attributes aria-required and aria-invalid for inputs

Tags
since
2.0.11

$addClass

public string $addClass = 'form-control'

CSS classname to add to the input

$addon

public array<string|int, mixed> $addon = []

addon to prepend or append to the widget (based on bootstrap input group styling).

  • prepend: array|string, the prepend addon configuration. If set as a string will be rendered as is. If set as an array, the following properties can be set:
    • content: string, the prepend addon content.
    • asButton: _boolean, whether the addon is a button or button group. Defaults to false`.
  • append: array|string, the append addon configuration. If set as a string will be rendered as is. If set as an array, the following properties can be set:
    • content: string, the append addon content.
    • asButton: _boolean, whether the addon is a button or button group. Defaults to false`.
  • preCaption : array|string, the addon content placed before the caption. Note that this property is applicable for [[Html5Input]] widget only. If set as a string, will be rendered as a raw markup without HTML encoding. If set as an array, the following options can be set:
    • content : string, the append addon content
    • asButton : boolean, whether the addon is a button
    • options : _array the HTML attributes for the append addon
  • contentBefore: string, content placed before the addon
  • contentAfter: string, content placed after the addon
  • groupOptions: array, HTML options for the input group

$attribute

public string $attribute

the model attribute that this field is associated with.

$autoOffset

public bool $autoOffset = true

whether to auto offset toggle inputs (checkboxes / radios) horizontal form layout for BS 4.x forms. This will read the labelSpan and automatically offset the checkboxes/radios.

$autoPlaceholder

public bool $autoPlaceholder

whether the label is to be hidden and auto-displayed as a placeholder

$behaviors read-only

public array<string|int, Behavior> $behaviors

List of behaviors attached to this component.

$checkEnclosedTemplate

public string $checkEnclosedTemplate = "{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}"

the template for rendering checkboxes and radios for a default Bootstrap markup with an enclosed label

$checkTemplate

public string $checkTemplate = "{input}\n{label}\n{error}\n{hint}"

the template for rendering checkboxes and radios for a default Bootstrap markup without an enclosed label

$checkWrapperOptions

public array<string|int, mixed> $checkWrapperOptions = []

the HTML attributes for the container wrapping BS4 checkbox or radio controls within which the content will be rendered via the [[checkTemplate]] or [[checkEnclosedTemplate]]

$contentAfterError

public string $contentAfterError = ''

content to be placed after error block

$contentAfterField

public string $contentAfterField = ''

content to be placed after field within the form group at the end

$contentAfterHint

public string $contentAfterHint = ''

content to be placed after hint block

$contentAfterInput

public string $contentAfterInput = ''

content to be placed after input

$contentAfterLabel

public string $contentAfterLabel = ''

content to be placed after label

$contentBeforeError

public string $contentBeforeError = ''

content to be placed before error block

$contentBeforeField

public string $contentBeforeField = ''

content to be placed before field within the form group at the beginning

$contentBeforeHint

public string $contentBeforeHint = ''

content to be placed before hint block

$contentBeforeInput

public string $contentBeforeInput = ''

content to be placed before input

$contentBeforeLabel

public string $contentBeforeLabel = ''

content to be placed before label

$deviceSize

public string $deviceSize

one of the bootstrap sizes (refer the ActiveForm::SIZE constants)

$enableAjaxValidation

public bool|null $enableAjaxValidation

whether to enable AJAX-based data validation. If not set, it will take the value of [[ActiveForm::enableAjaxValidation]].

$enableClientValidation

public bool|null $enableClientValidation

whether to enable client-side data validation. If not set, it will take the value of [[ActiveForm::enableClientValidation]].

$enableError

public bool $enableError

whether to render the error. Default is true except for layout inline.

$enableLabel

public bool $enableLabel

whether to render the label. Default is true.

$errorOptions

public array<string|int, mixed> $errorOptions = ['class' => 'help-block']

the default options for the error tags. The parameter passed to [[error()]] will be merged with this property when rendering the error tag. The following special options are recognized:

  • tag: the tag name of the container element. Defaults to div. Setting it to false will not render a container tag. See also [[\yii\helpers\Html::tag()]].
  • encode: whether to encode the error output. Defaults to true.

If you set a custom id for the error element, you may need to adjust the [[$selectors]] accordingly.

Tags
see
Html::renderTagAttributes()

for details on how attributes are being rendered.

$feedbackIcon

public array<string|int, mixed> $feedbackIcon = []

the feedback icon configuration (applicable for bootstrap text inputs). This must be setup as an array containing the following keys:

  • type: string, the icon type to use. Should be one of raw or icon. Defaults to icon, where the default, error and success settings will be treated as an icon CSS suffix name. If set to raw, they will be treated as a raw content markup.
  • prefix: string, the icon CSS class prefix to use if type is icon. Defaults to glyphicon glyphicon- for Bootstrap 3.x and fas fa- for Bootstrap 4.x and above.
  • default: string, the icon (CSS class suffix name or raw markup) to show by default. If not set will not be shown.
  • error: string, the icon (CSS class suffix name or raw markup) to use when input has an error validation. If not set will not be shown.
  • success: string, the icon (CSS class suffix name or raw markup) to use when input has a success validation. If not set will not be shown.
  • defaultOptions: array, the HTML attributes to apply for default icon. The special attribute description can be set to describe this feedback as an aria attribute for accessibility. Defaults to (default).
  • errorOptions: array, the HTML attributes to apply for error icon. The special attribute description can be set to describe this feedback as an aria attribute for accessibility. Defaults to (error).
  • successOptions: array, the HTML attributes to apply for success icon. The special attribute description can be set to describe this feedback as an aria attribute for accessibility. Defaults to (success).
Tags
see
http://getbootstrap.com/css/#with-optional-icons

$highlightAddon

public bool $highlightAddon = true

whether to highlight error and success states on input group addons automatically

$hintOptions

public array<string|int, mixed> $hintOptions = ['class' => 'hint-block']

the default options for the hint tags. The parameter passed to [[hint()]] will be merged with this property when rendering the hint tag. The following special options are recognized:

  • tag: the tag name of the container element. Defaults to div. Setting it to false will not render a container tag. See also [[\yii\helpers\Html::tag()]].
Tags
see
Html::renderTagAttributes()

for details on how attributes are being rendered.

$hintSettings

public array<string|int, mixed> $hintSettings = []

the settings for displaying the hint. These settings are parsed only if hintType is set to self::HINT_SPECIAL. The following properties are supported:

  • showIcon: boolean, whether to display the hint via a help icon indicator. Defaults to true.
  • icon: string, the markup to display the help icon. Defaults to
    • <i class="glyphicon glyphicon-question-sign text-info"></i> for Bootstrap 3.x.
    • <i class="fas fa-question-circle text-info"></i> for Bootstrap 4.x and above.
  • iconBesideInput: boolean, whether to display the icon beside the input. Defaults to false. The following actions will be taken based on this setting:
    • if set to false the help icon is displayed beside the label and the labelTemplate setting is used to render the icon and label markups.
    • if set to true the help icon is displayed beside the input and the inputTemplate setting is used to render the icon and input markups.
  • labelTemplate: string, the template to render the help icon and the field label. Defaults to {label}{help}, where
    • {label} will be replaced by the ActiveField label content
    • {help} will be replaced by the help icon indicator markup
  • inputTemplate: string, the template to render the help icon and the field input. Defaults to '<div style="width:90%; float:left">{input}</div><div style="padding-top:7px">{help}</div>',, where
    • {input} will be replaced by the ActiveField input content
    • {help} will be replaced by the help icon indicator markup
  • onLabelClick: boolean, whether to display the hint on clicking the label. Defaults to false.
  • onLabelHover: boolean, whether to display the hint on hover of the label. Defaults to true.
  • onIconClick: boolean, whether to display the hint on clicking the icon. Defaults to true.
  • onIconHover: boolean, whether to display the hint on hover of the icon. Defaults to false.
  • iconCssClass: string, the CSS class appended to the span container enclosing the icon.
  • labelCssClass: string, the CSS class appended to the span container enclosing label text within label tag.
  • contentCssClass: string, the CSS class appended to the span container displaying help content within popover.
  • hideOnEscape: boolean, whether to hide the popover on clicking escape button on the keyboard. Defaults to true.
  • hideOnClickOut: boolean, whether to hide the popover on clicking outside the popover. Defaults to true.
  • title: string, the title heading for the popover dialog. Defaults to empty string, whereby the heading is not displayed.
  • placement: string, the placement of the help popover on hover or click of the icon or label. Defaults to top.
  • container: string, the specific element to which the popover will be appended to. Defaults to table when iconBesideInput is true, else defaults to form
  • animation: boolean, whether to add a CSS fade transition effect when opening and closing the popover. Defaults to true.
  • delay``: _integer_|_array_, the number of milliseconds it will take to open and close the popover. Defaults to 0`.
  • selector: integer, the specified selector to add the popover to. Defaults to boolean false.
  • viewport: string|array, the element within which the popover will be bounded to. Defaults to ['selector' => 'body', 'padding' => 0].

$hintType

public int $hintType = self::HINT_DEFAULT

the hint display type. If set to self::HINT_DEFAULT, the hint will be displayed as a text block below each input. If set to self::HINT_SPECIAL, then the hintSettings will be applied to display the field hint.

$horizontalCssClasses

public null|array<string|int, mixed> $horizontalCssClasses

CSS grid classes for horizontal layout. This must be an array with these keys:

  • offset: the offset grid class to append to the wrapper if no label is rendered
  • label: the label grid class
  • wrapper: the wrapper grid class
  • error: the error grid class
  • hint: the hint grid class These options are compatible and similar to [[\yii\bootstrap\ActiveForm]] and provide a complete flexible container. If labelSpan is set in [[ActiveForm::formConfig]] and wrapper is also set, then both css options are concatenated. If wrapper contains a 'col-' class wrapper, it overrides the tag from labelSpan.

$inputOptions

public array<string|int, mixed> $inputOptions = ['class' => 'form-control']

the default options for the input tags. The parameter passed to individual input methods (e.g. [[textInput()]]) will be merged with this property when rendering the input tag.

If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.

Tags
see
Html::renderTagAttributes()

for details on how attributes are being rendered.

$labelOptions

public array<string|int, mixed> $labelOptions = []

the default options for the label tags. The parameter passed to [[label()]] will be merged with this property when rendering the label tag.

Tags
inheritdoc

$labelSpan

public int $labelSpan

the bootstrap grid column width (usually between 1 to 12)

$model

public Model $model

the data model that this field is associated with.

$options

public array<string|int, mixed> $options = ['class' => 'form-group']

the HTML attributes (name-value pairs) for the field container tag. The values will be HTML-encoded using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered. The following special options are recognized:

  • tag: the tag name of the container element. Defaults to div. Setting it to false will not render a container tag. See also [[\yii\helpers\Html::tag()]].

If you set a custom id for the container element, you may need to adjust the [[$selectors]] accordingly.

Tags
see
Html::renderTagAttributes()

for details on how attributes are being rendered.

$parts

public array<string|int, mixed> $parts = []

different parts of the field (e.g. input, label). This will be used together with [[template]] to generate the final field HTML code. The keys are the token names in [[template]], while the values are the corresponding HTML code. Valid tokens include {input}, {label} and {error}. Note that you normally don't need to access this property directly as it is maintained by various methods of this class.

$renderEmptyWrapper

public bool $renderEmptyWrapper = false

whether to render the wrapper in the template if [[wrapperOptions]] is empty.

$selectors

public array<string|int, mixed> $selectors = []

the jQuery selectors for selecting the container, input and error tags. The array keys should be container, input, and/or error, and the array values are the corresponding selectors. For example, ['input' => '#my-input'].

The container selector is used under the context of the form, while the input and the error selectors are used under the context of the container.

You normally do not need to set this property as the default selectors should work well for most cases.

$showErrors

public bool $showErrors

whether to show errors for the field

$showHints

public bool $showHints

whether to show hints for the field

$showLabels

public bool|string $showLabels

whether to show labels for the field. Should be one of the following values:

  • true: show labels for the field
  • false: hide labels for the field
  • ActiveForm::SCREEN_READER: show in screen reader only (hide from normal display)

$showRequiredIndicator

public bool $showRequiredIndicator = true

whether to show required asterisk/star indicator after each field label when the model attribute is set to have a required validation rule. This will add a CSS class has-star to the label and show the required asterisk/star after the label based on CSS ::after styles. If you want any other label markup to show a required asterisk for a required model attribute field, then just add the CSS class has-star to the label/span markup element within the active field container with CSS class form-group.

$skipFormLayout

public bool $skipFormLayout = false

whether to override the form layout styles and skip field formatting as per the form layout. Defaults to false.

$staticValue

public string $staticValue

the static value for the field to be displayed for the static input OR when the form is in staticOnly mode. This value is not HTML encoded.

$template

public string $template = "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}"

inherits and overrides values from parent class. The value can be overridden within [[ActiveForm::field()]] method. The following tokens are supported:

  • {beginLabel}: Container begin tag for labels (to be used typically along with {labelTitle} token when you do not wish to directly use the {label} token)
  • {labelTitle}: Label content without tags (to be used typically when you do not wish to directly use the {label token)
  • {endLabel}: Container end tag for labels (to be used typically along with {labelTitle} token when you do not wish to directly use the {label} token)
  • {label}: Full label tag with begin tag, content and end tag
  • {beginWrapper}: Container for input,error and hint start tag. Uses a <div> tag if there is a input wrapper CSS detected, else defaults to empty string.
  • {input}: placeholder for input control whatever it is
  • {hint}: placeholder for hint/help text including sub container
  • {error}: placeholder for error text including sub container
  • {endWrapper}: end tag for {beginWrapper}. Defaults to </div> if there is a input wrapper CSS detected, else defaults to empty string.

$validateOnBlur

public bool|null $validateOnBlur

whether to perform validation when the input field loses focus. If not set, it will take the value of [[ActiveForm::validateOnBlur]].

$validateOnChange

public bool|null $validateOnChange

whether to perform validation when the value of the input field is changed. If not set, it will take the value of [[ActiveForm::validateOnChange]].

$validateOnType

public bool|null $validateOnType

whether to perform validation while the user is typing in the input field. If not set, it will take the value of [[ActiveForm::validateOnType]].

Tags
see
validationDelay

$validationDelay

public int|null $validationDelay

number of milliseconds that the validation should be delayed when the user types in the field and [[validateOnType]] is set true. If not set, it will take the value of [[ActiveForm::validationDelay]].

$wrapperOptions

public array<string|int, mixed> $wrapperOptions = []

options for the wrapper tag, used in the {beginWrapper} token within [[template]].

$_hasFeedback

protected bool $_hasFeedback = false

whether there is a feedback icon configuration set

$_isHintSpecial

protected bool $_isHintSpecial = false

whether there is a feedback icon configuration set

$_isStatic

protected bool $_isStatic = false

is it a static input

$_multiselect

protected bool $_multiselect = ''

the container for multi select

$_offset

protected bool $_offset = false

whether the input is to be offset (like for checkbox or radio).

$_pluginHintKeys

protected static array<string|int, mixed> $_pluginHintKeys = ['iconCssClass', 'labelCssClass', 'contentCssClass', 'hideOnEscape', 'hideOnClickOut', 'title', 'placement', 'container', 'animation', 'delay', 'template', 'selector', 'viewport']

the list of hint keys that will be used by ActiveFieldHint jQuery plugin

$_settings

protected array<string|int, mixed> $_settings = ['input' => '{input}', 'error' => '{error}', 'hint' => '{hint}', 'showLabels' => true, 'showErrors' => true, 'labelSpan' => \kartik\form\ActiveForm::DEFAULT_LABEL_SPAN, 'deviceSize' => \kartik\form\ActiveForm::SIZE_MEDIUM]

the settings for the active field layout

$_behaviors

private array<string|int, Behavior>|null $_behaviors

the attached behaviors (behavior name => behavior). This is null when not initialized.

$_events

private array<string|int, mixed> $_events = []

the attached event handlers (event name => handlers)

$_eventWildcards

private array<string|int, mixed> $_eventWildcards = []

the event handlers attached for wildcard patterns (event name wildcard => handlers)

Tags
since
2.0.14

$_hintPopoverContainer

private string $_hintPopoverContainer

the identifier for the hint popover container.

$_iconBesideInput

private bool $_iconBesideInput = false

whether the hint icon is beside the input.

$_inputCss

private string $_inputCss

the input container additional css class for horizontal forms and special inputs like checkbox and radio.

$_inputId

private string $_inputId

this property holds a custom input id if it was set using [[inputOptions]] or in one of the $options parameters of the input* methods.

$_labelCss

private string $_labelCss

the label additional css class for horizontal forms and special inputs like checkbox and radio.

$_skipLabelFor

private bool $_skipLabelFor = false

if "for" field label attribute should be skipped.

Methods

__call()

Calls the named method which is not a class method.

public __call(string $name, array<string|int, mixed> $params) : mixed

This method will check if any attached behavior has the named method and will execute it if available.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

Parameters
$name : string

the method name

$params : array<string|int, mixed>

method parameters

Tags
throws
UnknownMethodException

when calling unknown method

Return values
mixed

the method return value

__clone()

This method is called after the object is created by cloning an existing one.

public __clone() : mixed

It removes all behaviors because they are attached to the old object.

__construct()

Constructor.

public __construct([mixed $config = [] ]) : mixed
Parameters
$config : mixed = []

name-value pairs that will be used to initialize the object properties

__get()

Returns the value of a component property.

public __get(string $name) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a getter: return the getter result
  • a property of a behavior: return the behavior property value

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $component->property;.

Parameters
$name : string

the property name

Tags
throws
UnknownPropertyException

if the property is not defined

throws
InvalidCallException

if the property is write-only.

see
__set()
Return values
mixed

the property value or the value of a behavior's property

__isset()

Checks if a property is set, i.e. defined and not null.

public __isset(string $name) : bool

This method will check in the following order and act accordingly:

  • a property defined by a setter: return whether the property is set
  • a property of a behavior: return whether the property is set
  • return false for non existing properties

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($component->property).

Parameters
$name : string

the property name or the event name

Tags
see
https://www.php.net/manual/en/function.isset.php
Return values
bool

whether the named property is set

__set()

Sets the value of a component property.

public __set(string $name, mixed $value) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value
  • an event in the format of "on xyz": attach the handler to the event "xyz"
  • a behavior in the format of "as xyz": attach the behavior named as "xyz"
  • a property of a behavior: set the behavior property value

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.

Parameters
$name : string

the property name or the event name

$value : mixed

the property value

Tags
throws
UnknownPropertyException

if the property is not defined

throws
InvalidCallException

if the property is read-only.

see
__get()

__toString()

PHP magic method that returns the string representation of this object.

public __toString() : string
Return values
string

the string representation of this object.

__unset()

Sets a component property to be null.

public __unset(string $name) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value to be null
  • a property of a behavior: set the property value to be null

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($component->property).

Parameters
$name : string

the property name

Tags
throws
InvalidCallException

if the property is read only.

see
https://www.php.net/manual/en/function.unset.php

attachBehavior()

Attaches a behavior to this component.

public attachBehavior(string $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior

This method will create the behavior object based on the given configuration. After that, the behavior object will be attached to this component by calling the [[Behavior::attach()]] method.

Parameters
$name : string

the name of the behavior.

$behavior : string|array<string|int, mixed>|Behavior

the behavior configuration. This can be one of the following:

  • a [[Behavior]] object
  • a string specifying the behavior class
  • an object configuration array that will be passed to [[Yii::createObject()]] to create the behavior object.
Tags
see
detachBehavior()
Return values
Behavior

the behavior object

attachBehaviors()

Attaches a list of behaviors to the component.

public attachBehaviors(array<string|int, mixed> $behaviors) : mixed

Each behavior is indexed by its name and should be a [[Behavior]] object, a string specifying the behavior class, or an configuration array for creating the behavior.

Parameters
$behaviors : array<string|int, mixed>

list of behaviors to be attached to the component

Tags
see
attachBehavior()

begin()

Renders the opening tag of the field container.

public begin() : string
Tags
inheritdoc
Return values
string

the rendering result.

behaviors()

Returns a list of behaviors that this component should behave as.

public behaviors() : array<string|int, mixed>

Child classes may override this method to specify the behaviors they want to behave as.

The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

Note that a behavior class must extend from [[Behavior]]. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using [[getBehavior()]] or be detached using [[detachBehavior()]]. Anonymous behaviors can not be retrieved or detached.

Behaviors declared in this method will be attached to the component automatically (on demand).

Return values
array<string|int, mixed>

the behavior configurations.

canGetProperty()

Returns a value indicating whether a property can be read.

public canGetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property can be read if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a readable property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canSetProperty()
Return values
bool

whether the property can be read

canSetProperty()

Returns a value indicating whether a property can be set.

public canSetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property can be written if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a writable property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canGetProperty()
Return values
bool

whether the property can be written

checkbox()

Renders a checkbox. This method will generate the "checked" tag attribute according to the model attribute value.

public checkbox([array<string|int, mixed> $options = [] ][, bool|null $enclosedByLabel = null ]) : ActiveField
Parameters
$options : array<string|int, mixed> = []

the tag options in terms of name-value pairs. The following options are specially handled:

  • custom: bool, whether to render bootstrap 4.x custom checkbox styled control. Defaults to false. This is applicable only for Bootstrap 4.x forms.
  • switch: bool, whether to render bootstrap 4.x custom switch styled control. Defaults to false. This is applicable only for Bootstrap 4.x forms.
$enclosedByLabel : bool|null = null

whether to enclose the radio within the label. If true, the method will still use [[template]] to layout the checkbox and the error message except that the radio is enclosed by the label tag.

Tags
throws
InvalidConfigException
see
https://getbootstrap.com/docs/4.1/components/forms/#checkboxes-and-radios-1
  • uncheck: string, the value associated with the uncheck state of the checkbox. If not set, it will take the default value 0. This method will render a hidden input so that if the checkbox is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input.
  • label: string, a label displayed next to the checkbox. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should [[Html::encode()]] it to prevent XSS attacks. When this option is specified, the checkbox will be enclosed by a label tag.
  • labelOptions: array, the HTML attributes for the label tag. This is only used when the "label" option is specified.
  • container: boolean|array, the HTML attributes for the checkbox container. If this is set to false, no container will be rendered. The special option tagwill be recognized which defaults todiv. This defaults to: ['tag' => 'div', 'class'=>'radio']` The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered.
Return values
ActiveField

object

checkboxButtonGroup()

Renders a list of checkbox toggle buttons.

public checkboxButtonGroup(array<string|int, mixed> $items[, array<string|int, mixed> $options = [] ]) : ActiveField
Parameters
$items : array<string|int, mixed>

the data item used to generate the checkboxes. The array values are the labels, while the array keys are the corresponding checkbox values. Note that the labels will NOT be HTML-encoded, while the values will.

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

options (name => config) for the checkbox button list. The following options are specially handled:

  • unselect: string, the value that should be submitted when none of the checkboxes is selected. By setting this option, a hidden input will be generated. If you do not want any hidden input, you should explicitly set this option as null.
  • separator: string, the HTML code that separates items.
  • `item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:
function ($index, $label, $name, $checked, $value)

where $index is the zero-based index of the checkbox button in the whole list; $label is the label for the checkbox button; and $name, $value and $checked represent the name, value and the checked status of the checkbox button input.

Tags
see
http://getbootstrap.com/javascript/#buttons-checkbox-radio
throws
InvalidConfigException
Return values
ActiveField

object

checkboxList()

Renders a list of checkboxes. A checkbox list allows multiple selection, like [[listBox()]]. As a result, the corresponding submitted value is an array. The selection of the checkbox list is taken from the value of the model attribute.

public checkboxList(array<string|int, mixed> $items[, array<string|int, mixed> $options = [] ]) : ActiveField
Parameters
$items : array<string|int, mixed>

the data item used to generate the checkboxes. The array values are the labels, while the array keys are the corresponding checkbox values. Note that the labels will NOT be HTML-encoded, while the values will be encoded.

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

options (name => config) for the checkbox list. The following options are specially handled:

  • custom: bool, whether to render bootstrap 4.x custom checkbox/radio styled control. Defaults to false. This is applicable only for Bootstrap 4.x forms.
Tags
throws
InvalidConfigException
see
https://getbootstrap.com/docs/4.1/components/forms/#checkboxes-and-radios-1
  • unselect: string, the value that should be submitted when none of the checkboxes is selected. By setting this option, a hidden input will be generated.
  • separator: string, the HTML code that separates items.
  • inline: boolean, whether the list should be displayed as a series on the same line, default is false
  • `item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:
function ($index, $label, $name, $checked, $value)

where $index is the zero-based index of the checkbox in the whole list; $label is the label for the checkbox; and $name, $value and $checked represent the name, value and the checked status of the checkbox input.

Return values
ActiveField

object

className()

Returns the fully qualified name of this class.

public static className() : string
Tags
deprecated

since 2.0.14. On PHP >=5.5, use ::class instead.

Return values
string

the fully qualified name of this class.

detachBehavior()

Detaches a behavior from the component.

public detachBehavior(string $name) : Behavior|null

The behavior's [[Behavior::detach()]] method will be invoked.

Parameters
$name : string

the behavior's name.

Return values
Behavior|null

the detached behavior. Null if the behavior does not exist.

detachBehaviors()

Detaches all behaviors from the component.

public detachBehaviors() : mixed

dropDownList()

Renders a drop-down list.

public dropDownList(mixed $items[, mixed $options = [] ]) : $this
Parameters
$items : mixed

the option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [[ArrayHelper::map()]].

Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded.

$options : mixed = []

the tag options in terms of name-value pairs.

For the list of available options please refer to the $options parameter of [[\yii\helpers\Html::activeDropDownList()]].

If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.

Tags
inheritdoc
throws
InvalidConfigException
Return values
$this

the field object itself.

end()

Renders the closing tag of the field container.

public end() : string
Tags
inheritdoc
Return values
string

the rendering result.

ensureBehaviors()

Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.

public ensureBehaviors() : mixed

error()

Generates a tag that contains the first validation error of [[attribute]].

public error([array<string|int, mixed>|false $options = [] ]) : $this

Note that even if there is no validation error, this method will still return an empty error tag.

Parameters
$options : array<string|int, mixed>|false = []

the tag options in terms of name-value pairs. It will be merged with [[errorOptions]]. The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. If this parameter is false, no error tag will be rendered.

The following options are specially handled:

  • tag: this specifies the tag name. If not set, div will be used. See also [[\yii\helpers\Html::tag()]].

If you set a custom id for the error element, you may need to adjust the [[$selectors]] accordingly.

Tags
see
errorOptions
Return values
$this

the field object itself.

fileInput()

Renders a file input.

public fileInput([mixed $options = [] ]) : $this
Parameters
$options : mixed = []

the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].

If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.

Tags
inheritdoc
throws
InvalidConfigException
Return values
$this

the field object itself.

getBehavior()

Returns the named behavior object.

public getBehavior(string $name) : Behavior|null
Parameters
$name : string

the behavior name

Return values
Behavior|null

the behavior object, or null if the behavior does not exist

getBehaviors()

Returns all behaviors attached to this component.

public getBehaviors() : array<string|int, Behavior>
Return values
array<string|int, Behavior>

list of behaviors attached to this component

hasEventHandlers()

Returns a value indicating whether there is any handler attached to the named event.

public hasEventHandlers(string $name) : bool
Parameters
$name : string

the event name

Return values
bool

whether there is any handler attached to the event.

hasMethod()

Returns a value indicating whether a method is defined.

public hasMethod(string $name[, bool $checkBehaviors = true ]) : bool

A method is defined if:

  • the class has a method with the specified name
  • an attached behavior has a method with the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkBehaviors : bool = true

whether to treat behaviors' methods as methods of this component

Return values
bool

whether the method is defined

hasProperty()

Returns a value indicating whether a property is defined for this component.

public hasProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canGetProperty()
see
canSetProperty()
Return values
bool

whether the property is defined

hiddenInput()

Renders a hidden input.

public hiddenInput([array<string|int, mixed> $options = [] ]) : $this

Note that this method is provided for completeness. In most cases because you do not need to validate a hidden input, you should not need to use this method. Instead, you should use [[\yii\helpers\Html::activeHiddenInput()]].

This method will generate the name and value tag attributes automatically for the model attribute unless they are explicitly specified in $options.

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

the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].

If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.

Return values
$this

the field object itself.

hint()

Renders the hint tag.

public hint(mixed $content[, mixed $options = [] ]) : $this
Parameters
$content : mixed

the hint content. If null, the hint will be generated via [[Model::getAttributeHint()]]. If false, the generated field will not contain the hint part. Note that this will NOT be [[Html::encode()|encoded]].

$options : mixed = []

the tag options in terms of name-value pairs. These will be rendered as the attributes of the hint tag. The values will be HTML-encoded using [[Html::encode()]].

The following options are specially handled:

  • tag: this specifies the tag name. If not set, div will be used. See also [[\yii\helpers\Html::tag()]].
Tags
inheritdoc
Return values
$this

the field object itself.

input()

Renders an input tag.

public input(mixed $type[, mixed $options = [] ]) : $this
Parameters
$type : mixed

the input type (e.g. text, password)

$options : mixed = []

the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].

If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.

Tags
inheritdoc
throws
InvalidConfigException
Return values
$this

the field object itself.

label()

Generates a label tag for [[attribute]].

public label([mixed $label = null ][, mixed $options = [] ]) : $this
Parameters
$label : mixed = null

the label to use. If null, the label will be generated via [[Model::getAttributeLabel()]]. If false, the generated field will not contain the label part. Note that this will NOT be [[Html::encode()|encoded]].

$options : mixed = []

the tag options in terms of name-value pairs. It will be merged with [[labelOptions]]. The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered.

Tags
inheritdoc
Return values
$this

the field object itself.

listBox()

Renders a list box.

public listBox(mixed $items[, mixed $options = [] ]) : $this
Parameters
$items : mixed

the option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [[\yii\helpers\ArrayHelper::map()]].

Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded.

$options : mixed = []

the tag options in terms of name-value pairs.

For the list of available options please refer to the $options parameter of [[\yii\helpers\Html::activeListBox()]].

If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.

Tags
inheritdoc
throws
InvalidConfigException
Return values
$this

the field object itself.

multiselect()

Renders a multi select list box. This control extends the checkboxList and radioList available in [[YiiActiveField]] - to display a scrolling multi select list box.

public multiselect(array<string|int, mixed> $items[, array<string|int, mixed> $options = [] ]) : ActiveField
Parameters
$items : array<string|int, mixed>

the data item used to generate the checkboxes or radio.

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

the options for checkboxList or radioList. Additional parameters

  • height: string, the height of the multiselect control - defaults to 145px
  • selector: string, whether checkbox or radio - defaults to checkbox
  • container: array, options for the multiselect container
  • unselect: string, the value that should be submitted when none of the radio buttons is selected. By setting this option, a hidden input will be generated.
  • separator: string, the HTML code that separates items.
  • `item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:
  • inline: boolean, whether the list should be displayed as a series on the same line, default is false
  • selector: string, whether the selection input is [[TYPE_RADIO]] or [[TYPE_CHECKBOX]]
Tags
throws
InvalidConfigException
Return values
ActiveField

object

off()

Detaches an existing event handler from this component.

public off(string $name[, callable|null $handler = null ]) : bool

This method is the opposite of [[on()]].

Note: in case wildcard pattern is passed for event name, only the handlers registered with this wildcard will be removed, while handlers registered with plain names matching this wildcard will remain.

Parameters
$name : string

event name

$handler : callable|null = null

the event handler to be removed. If it is null, all handlers attached to the named event will be removed.

Tags
see
on()
Return values
bool

if a handler is found and detached

on()

Attaches an event handler to an event.

public on(string $name, callable $handler[, mixed $data = null ][, bool $append = true ]) : mixed

The event handler must be a valid PHP callback. The following are some examples:

function ($event) { ... }         // anonymous function
[$object, 'handleClick']          // $object->handleClick()
['Page', 'handleClick']           // Page::handleClick()
'handleClick'                     // global function handleClick()

The event handler must be defined with the following signature,

function ($event)

where $event is an [[Event]] object which includes parameters associated with the event.

Since 2.0.14 you can specify event name as a wildcard pattern:

$component->on('event.group.*', function ($event) {
    Yii::trace($event->name . ' is triggered.');
});
Parameters
$name : string

the event name

$handler : callable

the event handler

$data : mixed = null

the data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via [[Event::data]].

$append : bool = true

whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list.

Tags
see
off()

passwordInput()

Renders a password input.

public passwordInput([mixed $options = [] ]) : $this
Parameters
$options : mixed = []

the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].

If you set a custom id for the input element, you may need to adjust the [[$selectors]] accordingly.

Tags
inheritdoc
throws
InvalidConfigException
Return values
$this

the field object itself.

radio()

Renders a radio button. This method will generate the "checked" tag attribute according to the model attribute value.

public radio([array<string|int, mixed> $options = [] ][, bool|null $enclosedByLabel = null ]) : ActiveField
Parameters
$options : array<string|int, mixed> = []

the tag options in terms of name-value pairs. The following options are specially handled:

  • custom: bool, whether to render bootstrap 4.x custom radio styled control. Defaults to false. This is applicable only for Bootstrap 4.x forms.
$enclosedByLabel : bool|null = null

whether to enclose the radio within the label. If true, the method will still use [[template]] to layout the checkbox and the error message except that the radio is enclosed by the label tag.

Tags
throws
InvalidConfigException
see
https://getbootstrap.com/docs/4.1/components/forms/#checkboxes-and-radios-1
  • uncheck: string, the value associated with the uncheck state of the radio button. If not set, it will take the default value '0'. This method will render a hidden input so that if the radio button is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input.
  • label: string, a label displayed next to the radio button. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should [[Html::encode()]] it to prevent XSS attacks. When this option is specified, the radio button will be enclosed by a label tag.
  • labelOptions: array, the HTML attributes for the label tag. This is only used when the "label" option is specified.
  • container: boolean|array, the HTML attributes for the checkbox container. If this is set to false, no container will be rendered. The special option tagwill be recognized which defaults todiv. This defaults to: ['tag' => 'div', 'class'=>'radio']` The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered.
Return values
ActiveField

object

radioButtonGroup()

Renders a list of radio toggle buttons.

public radioButtonGroup(array<string|int, mixed> $items[, array<string|int, mixed> $options = [] ]) : ActiveField
Parameters
$items : array<string|int, mixed>

the data item used to generate the radios. The array values are the labels, while the array keys are the corresponding radio values. Note that the labels will NOT be HTML-encoded, while the values will be encoded.

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

options (name => config) for the radio button list. The following options are specially handled:

  • unselect: string, the value that should be submitted when none of the radios is selected. By setting this option, a hidden input will be generated. If you do not want any hidden input, you should explicitly set this option as null.
  • separator: string, the HTML code that separates items.
  • `item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:
function ($index, $label, $name, $checked, $value)

where $index is the zero-based index of the radio button in the whole list; $label is the label for the radio button; and $name, $value and $checked represent the name, value and the checked status of the radio button input.

Tags
see
http://getbootstrap.com/javascript/#buttons-checkbox-radio
throws
InvalidConfigException
Return values
ActiveField

object

radioList()

Renders a list of radio buttons. A radio button list is like a checkbox list, except that it only allows single selection. The selection of the radio buttons is taken from the value of the model attribute.

public radioList(array<string|int, mixed> $items[, array<string|int, mixed> $options = [] ]) : ActiveField
Parameters
$items : array<string|int, mixed>

the data item used to generate the radio buttons. The array keys are the labels, while the array values are the corresponding radio button values. Note that the labels will NOT be HTML-encoded, while the values will.

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

options (name => config) for the radio button list. The following options are specially handled:

  • custom: bool, whether to render bootstrap 4.x custom checkbox/radio styled control. Defaults to false. This is applicable only for Bootstrap 4.x forms.
Tags
throws
InvalidConfigException
see
https://getbootstrap.com/docs/4.1/components/forms/#checkboxes-and-radios-1
  • unselect: string, the value that should be submitted when none of the radio buttons is selected. By setting this option, a hidden input will be generated.
  • separator: string, the HTML code that separates items.
  • inline: boolean, whether the list should be displayed as a series on the same line, default is false
  • `item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:
function ($index, $label, $name, $checked, $value)

where $index is the zero-based index of the radio button in the whole list; $label is the label for the radio button; and $name, $value and $checked represent the name, value and the checked status of the radio button input.

Return values
ActiveField

object

render()

Renders the whole field.

public render([mixed $content = null ]) : string
Parameters
$content : mixed = null

the content within the field container. If null (not set), the default methods will be called to generate the label, error tag and input tag, and use them as the content. If a callable, it will be called to generate the content. The signature of the callable should be:

function ($field) {
    return $html;
}
Tags
inheritdoc
throws
InvalidConfigException
Return values
string

the rendering result.

staticInput()

Renders a static input (display only).

public staticInput([array<string|int, mixed> $options = [] ]) : ActiveField
Parameters
$options : array<string|int, mixed> = []

the tag options in terms of name-value pairs.

Tags
throws
Exception
Return values
ActiveField

object

textarea()

Renders a text area.

public textarea([mixed $options = [] ]) : $this
Parameters
$options : mixed = []

the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].

If you set a custom id for the textarea element, you may need to adjust the [[$selectors]] accordingly.

Tags
inheritdoc
throws
InvalidConfigException
Return values
$this

the field object itself.

textInput()

Renders a text input.

public textInput([mixed $options = [] ]) : $this
Parameters
$options : mixed = []

the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].

The following special options are recognized:

  • maxlength: int|bool, when maxlength is set true and the model attribute is validated by a string validator, the maxlength option will take the value of [[\yii\validators\StringValidator::max]]. This is available since version 2.0.3.

Note that if you set a custom id for the input element, you may need to adjust the value of [[selectors]] accordingly.

Tags
inheritdoc
throws
InvalidConfigException
Return values
$this

the field object itself.

trigger()

Triggers an event.

public trigger(string $name[, Event|null $event = null ]) : mixed

This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.

Parameters
$name : string

the event name

$event : Event|null = null

the event instance. If not set, a default [[Event]] object will be created.

widget()

Renders a widget as the input of the field.

public widget(mixed $class[, mixed $config = [] ]) : $this
Parameters
$class : mixed

the widget class name.

$config : mixed = []

name-value pairs that will be used to initialize the widget.

Tags
inheritdoc
Return values
$this

the field object itself.

addAriaAttributes()

Adds aria attributes to the input options.

protected addAriaAttributes(mixed &$options) : mixed
Parameters
$options : mixed

array input options

Tags
since
2.0.11

addErrorClassBS4()

Adds Bootstrap 4 validation class to the input options if needed.

protected addErrorClassBS4(array<string|int, mixed> &$options) : mixed
Parameters
$options : array<string|int, mixed>
Tags
throws
Exception

addErrorClassIfNeeded()

Adds validation class to the input options if needed.

protected addErrorClassIfNeeded(mixed &$options) : mixed
Parameters
$options : mixed

array input options

Tags
since
2.0.14

addRoleAttributes()

Add role attributes to the input options

protected addRoleAttributes(mixed &$options, string $role) : mixed
Parameters
$options : mixed

array input options

$role : string
Tags
since
2.0.16

adjustLabelFor()

Adjusts the `for` attribute for the label based on the input options.

protected adjustLabelFor(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

the input options.

buildLayoutParts()

Builds the field layout parts

protected buildLayoutParts(bool $showLabels, bool $showErrors) : mixed
Parameters
$showLabels : bool

whether to show labels

$showErrors : bool

whether to show errors

Tags
throws
InvalidConfigException

buildTemplate()

Builds the final template based on the bootstrap form type, display settings for label, error, and hint, and content before and after label, input, error, and hint.

protected buildTemplate() : mixed
Tags
throws
InvalidConfigException

createLayoutConfig()

Create layout specific configuration

protected createLayoutConfig([array<string|int, mixed> $instanceConfig = [] ]) : array<string|int, mixed>
Parameters
$instanceConfig : array<string|int, mixed> = []

the configuration passed to this instance's constructor

Return values
array<string|int, mixed>

the layout specific default configuration for this instance

generateHint()

Generates the hint.

protected generateHint([string $content = null ]) : string
Parameters
$content : string = null

the hint content

Return values
string

getAddonContent()

Parses and returns addon content.

protected getAddonContent(string $type[, int|null $bsVer = null ]) : string
Parameters
$type : string

the addon type prepend or append. If any other value is set, it will default to prepend

$bsVer : int|null = null

bootstrap version

Tags
throws
Exception
Return values
string

getClientOptions()

Returns the JS options for the field.

protected getClientOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>

the JS options.

getColCss()

Gets bootstrap grid column CSS based on size

protected getColCss(string $size) : string
Parameters
$size : string
Tags
throws
InvalidConfigException|Exception
Return values
string

getConfigParam()

Gets configuration parameter from formConfig

protected getConfigParam(string $param[, mixed $default = true ]) : string|bool
Parameters
$param : string

the parameter name

$default : mixed = true

the default parameter value

Tags
throws
Exception
Return values
string|bool

the parsed parameter value

getCustomCss()

Gets custom CSS for custom controls supported in bootstrap 4.x and 5.x

protected getCustomCss(string $type) : string
Parameters
$type : string
Tags
throws
Exception
Return values
string

getFeedbackIcon()

Generates a feedback icon

protected getFeedbackIcon(array<string|int, mixed> $config, string $cat, string $type, string $prefix, string $id) : string
Parameters
$config : array<string|int, mixed>

the feedback icon configuration

$cat : string

the feedback icon category

$type : string

the feedback icon type

$prefix : string

the feedback icon prefix

$id : string

the input attribute identifier

Tags
throws
Exception
Return values
string

getHintData()

Gets a hint configuration setting value

protected getHintData(string $key[, mixed $default = null ]) : mixed
Parameters
$key : string

the hint setting key to fetch

$default : mixed = null

the default value if not set

Tags
throws
Exception

getHintIcon()

Generates the hint icon

protected getHintIcon() : string
Tags
throws
Exception
Return values
string

getHintIconCss()

Gets the hint icon css based on `hintSettings`

protected getHintIconCss(string $type) : array<string|int, mixed>
Parameters
$type : string

whether Label or Icon

Return values
array<string|int, mixed>

the css to be applied

getInputId()

Returns the HTML `id` of the input element of this form field.

protected getInputId() : string
Tags
since
2.0.7
Return values
string

the input id.

getToggleField()

Generates a toggle field (checkbox or radio)

protected getToggleField([string $type = self::TYPE_CHECKBOX ][, array<string|int, mixed> $options = [] ][, bool|null $enclosedByLabel = null ]) : ActiveField
Parameters
$type : string = self::TYPE_CHECKBOX

the toggle input type 'checkbox' or 'radio'.

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

options (name => config) for the toggle input list container tag.

$enclosedByLabel : bool|null = null

whether the input is enclosed by the label tag

Tags
throws
InvalidConfigException
Return values
ActiveField

object

getToggleFieldList()

Renders a list of checkboxes / radio buttons. The selection of the checkbox / radio buttons is taken from the value of the model attribute.

protected getToggleFieldList(string $type, array<string|int, mixed> $items[, array<string|int, mixed> $options = [] ][, bool $asBtnGrp = false ]) : ActiveField
Parameters
$type : string

the toggle input type 'checkbox' or 'radio'.

$items : array<string|int, mixed>

the data item used to generate the checkbox / radio buttons. The array keys are the labels, while the array values are the corresponding checkbox / radio button values. Note that the labels will NOT be HTML-encoded, while the values will be encoded.

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

options (name => config) for the checkbox / radio button list. The following options are specially handled:

  • custom: bool, whether to render bootstrap 4.x custom checkbox/radio styled control. Defaults to false. This is applicable only for Bootstrap 4.x forms.
$asBtnGrp : bool = false

whether to generate the toggle list as a bootstrap button group

Tags
throws
InvalidConfigException
see
https://getbootstrap.com/docs/4.1/components/forms/#checkboxes-and-radios-1
  • unselect: string, the value that should be submitted when none of the checkbox / radio buttons is selected. By setting this option, a hidden input will be generated.
  • separator: string, the HTML code that separates items.
  • inline: boolean, whether the list should be displayed as a series on the same line, default is false
  • disabledItems: array, the list of values that will be disabled.
  • readonlyItems: array, the list of values that will be readonly.
  • `item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:
function ($index, $label, $name, $checked, $value)

where $index is the zero-based index of the checkbox/ radio button in the whole list; $label is the label for the checkbox/ radio button; and $name, $value and $checked represent the name, value and the checked status of the checkbox/ radio button input.

Return values
ActiveField

object

hasLabels()

Validate label display status

protected hasLabels() : bool|string
Tags
throws
Exception
Return values
bool|string

whether labels are to be shown

initDisability()

Validates and sets disabled or readonly inputs

protected initDisability(array<string|int, mixed> &$options) : mixed
Parameters
$options : array<string|int, mixed>

the HTML attributes for the input

initFieldOptions()

Initializes sizes and placeholder based on $autoPlaceholder

protected initFieldOptions(array<string|int, mixed> &$options) : mixed
Parameters
$options : array<string|int, mixed>

the HTML attributes for the input

Tags
throws
InvalidConfigException

initFieldSize()

Initializes field by detecting the bootstrap CSS size and sets a size modifier CSS to the field container

protected initFieldSize(array<string|int, mixed> $options, string $size) : mixed
Parameters
$options : array<string|int, mixed>

the HTML options

$size : string

the size to init

Tags
throws
InvalidConfigException|Exception

initHorizontal()

Prepares bootstrap grid col classes for horizontal layout including label and input tags and initiate private CSS variables. The process order for 'labelSpan' and 'wrapper' is as follows:

protected initHorizontal() : mixed
  • Step 1: Check $labelSpan and $deviceSize.
  • Step 2: Check `formConfig(['labelSpan' => x, 'deviceSize' => xy]) and build css tag.
  • If horizontalCssClasses['wrapper'] is set and no 'col-' tag then add this to css tag from Step 1.
  • If horizontalCssClasses['wrapper'] is set and wrapper has 'col-' tag then override css tag completely.
  • If no $labelSpan and no horizontalCssClasses['wrapper'] is set then use default from [[$_settings]]. Similar behavior to horizontalCssClasses['label'].
Tags
throws
InvalidConfigException

initLabels()

Initialize label options

protected initLabels() : mixed

initLayout()

Initialize layout settings for label, input, error and hint blocks and for various bootstrap 3 form layouts

protected initLayout() : mixed
Tags
throws
InvalidConfigException

isAjaxValidationEnabled()

Checks if ajax validation enabled for the field.

protected isAjaxValidationEnabled() : bool
Tags
since
2.0.11
Return values
bool

isClientValidationEnabled()

Checks if client validation enabled for the field.

protected isClientValidationEnabled() : bool
Tags
since
2.0.11
Return values
bool

isCustomControl()

Checks whether bootstrap 4.x custom control based on `options` parameter

protected isCustomControl(array<string|int, mixed> &$options) : bool
Parameters
$options : array<string|int, mixed>

HTML attributes for the control

Tags
throws
InvalidConfigException|Exception
Return values
bool

mergeSettings()

Merges the parameters for layout settings

protected mergeSettings(bool $showLabels, bool $showErrors) : mixed
Parameters
$showLabels : bool

whether to show labels

$showErrors : bool

whether to show errors

parseFormFlag()

Parses the form flag (for disabled/readonly).

protected parseFormFlag(string $flag, array<string|int, mixed> &$options) : void
Parameters
$flag : string
$options : array<string|int, mixed>

renderAddonItem()

Renders an addon item based on its configuration

protected static renderAddonItem(array<string|int, mixed> $config[, int|null $bsVer = null ]) : string
Parameters
$config : array<string|int, mixed>

the addon item configuration

$bsVer : int|null = null

bootstrap version

Tags
throws
Exception
Return values
string

renderLabelParts()

Render the label parts

protected renderLabelParts([string|null $label = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$label : string|null = null

the label or null to use model label

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

the tag options

setHintData()

Sets a hint property setting as a data attribute within `self::$options`

protected setHintData(string $key) : mixed
Parameters
$key : string

the hint property key

setLayoutContainer()

Sets the layout element container

protected setLayoutContainer(string $type[, string $css = '' ][, bool $chk = true ]) : mixed
Parameters
$type : string

the layout element type

$css : string = ''

the css class for the container

$chk : bool = true

whether to create the container for the layout element

attachBehaviorInternal()

Attaches a behavior to this component.

private attachBehaviorInternal(string|int $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior
Parameters
$name : string|int

the name of the behavior. If this is an integer, it means the behavior is an anonymous one. Otherwise, the behavior is a named one and any existing behavior with the same name will be detached first.

$behavior : string|array<string|int, mixed>|Behavior

the behavior to be attached

Return values
Behavior

the attached behavior.


        
On this page

Search results