Class kartik\form\ActiveField

Inheritancekartik\form\ActiveField » yii\widgets\ActiveField » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Uses Traitskartik\base\AddonTrait
Subclasseskartik\widgets\ActiveField
Available since version1.0

ActiveField represents a form input field within an kartik\form\ActiveForm and extends the yii\widgets\ActiveField component to handle various bootstrap functionality like form types, input groups/addons, toggle buttons, feedback icons, and other enhancements.

For example,

// $form is your active form instance
echo $form->field($model, 'email', ['addon' => ['type'=>'prepend', 'content'=>'@']]);
echo $form->field($model, 'amount_paid', ['addon' => ['type'=>'append', 'content'=>'.00']]);
echo $form->field($model, 'phone', [
    'addon' => [
        'type'=>'prepend',
        'content'=>'<i class="fas fa-mobile-alt"></i>'
    ]
]);

Usage example with horizontal form and advanced field layout CSS configuration:

echo $form->field($model, 'email', ['labelSpan' => 2, 'deviceSize' => ActiveForm::SIZE_SMALL]]);
echo $form->field($model, 'amount_paid', ['horizontalCssClasses' => ['wrapper' => 'hidden-xs']]);
echo $form->field($model, 'phone', [
    'horizontalCssClasses' => ['label' => 'col-md-2 col-sm-3 col-xs-12 myRedClass']
]);
echo $form->field($model, 'special', [
    'template' => '{beginLabel}For: {labelTitle}{endLabel}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}'
]);

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$addAriaAttributes boolean Adds aria HTML attributes aria-required and aria-invalid for inputs yii\widgets\ActiveField
$addClass string CSS classname to add to the input kartik\form\ActiveField
$addon array Addon to prepend or append to the widget (based on bootstrap input group styling). kartik\base\AddonTrait
$attribute string The model attribute that this field is associated with. yii\widgets\ActiveField
$autoOffset boolean Whether to auto offset toggle inputs (checkboxes / radios) horizontal form layout for BS 4. kartik\form\ActiveField
$autoPlaceholder boolean Whether the label is to be hidden and auto-displayed as a placeholder kartik\form\ActiveField
$behaviors yii\base\Behavior[] List of behaviors attached to this component. yii\base\Component
$checkEnclosedTemplate string The template for rendering checkboxes and radios for a default Bootstrap markup with an enclosed label kartik\form\ActiveField
$checkTemplate string The template for rendering checkboxes and radios for a default Bootstrap markup without an enclosed label kartik\form\ActiveField
$checkWrapperOptions array The HTML attributes for the container wrapping BS4 checkbox or radio controls within which the content will be rendered via the $checkTemplate or $checkEnclosedTemplate kartik\form\ActiveField
$contentAfterError string Content to be placed after error block kartik\form\ActiveField
$contentAfterField string Content to be placed after field within the form group at the end kartik\form\ActiveField
$contentAfterHint string Content to be placed after hint block kartik\form\ActiveField
$contentAfterInput string Content to be placed after input kartik\form\ActiveField
$contentAfterLabel string Content to be placed after label kartik\form\ActiveField
$contentBeforeError string Content to be placed before error block kartik\form\ActiveField
$contentBeforeField string Content to be placed before field within the form group at the beginning kartik\form\ActiveField
$contentBeforeHint string Content to be placed before hint block kartik\form\ActiveField
$contentBeforeInput string Content to be placed before input kartik\form\ActiveField
$contentBeforeLabel string Content to be placed before label kartik\form\ActiveField
$customFileTemplate string The template for rendering the Bootstrap 4. kartik\form\ActiveField
$deviceSize string One of the bootstrap sizes (refer the ActiveForm::SIZE constants) kartik\form\ActiveField
$enableAjaxValidation boolean|null Whether to enable AJAX-based data validation. yii\widgets\ActiveField
$enableClientValidation boolean|null Whether to enable client-side data validation. yii\widgets\ActiveField
$enableError boolean Whether to render the error. kartik\form\ActiveField
$enableLabel boolean Whether to render the label. kartik\form\ActiveField
$errorOptions array The default options for the error tags. yii\widgets\ActiveField
$feedbackIcon array The feedback icon configuration (applicable for [bootstrap text inputs](http://getbootstrap. kartik\form\ActiveField
$form kartik\form\ActiveForm kartik\form\ActiveField
$highlightAddon boolean Whether to highlight error and success states on input group addons automatically kartik\form\ActiveField
$hintOptions array The default options for the hint tags. yii\widgets\ActiveField
$hintSettings array The settings for displaying the hint. kartik\form\ActiveField
$hintType integer The hint display type. kartik\form\ActiveField
$horizontalCssClasses null|array CSS grid classes for horizontal layout. kartik\form\ActiveField
$inputOptions array The default options for the input tags. yii\widgets\ActiveField
$labelOptions array The default options for the label tags. kartik\form\ActiveField
$labelSpan integer The bootstrap grid column width (usually between 1 to 12) kartik\form\ActiveField
$model yii\base\Model The data model that this field is associated with. yii\widgets\ActiveField
$options array The HTML attributes (name-value pairs) for the field container tag. yii\widgets\ActiveField
$parts array Different parts of the field (e.g. input, label). yii\widgets\ActiveField
$renderEmptyWrapper boolean Whether to render the wrapper in the template if $wrapperOptions is empty. kartik\form\ActiveField
$selectors array The jQuery selectors for selecting the container, input and error tags. yii\widgets\ActiveField
$showErrors boolean Whether to show errors for the field kartik\form\ActiveField
$showHints boolean Whether to show hints for the field kartik\form\ActiveField
$showLabels boolean|string Whether to show labels for the field. kartik\form\ActiveField
$showRequiredIndicator boolean Whether to show required asterisk/star indicator after each field label when the model attribute is set to have a required validation rule. kartik\form\ActiveField
$skipFormLayout boolean Whether to override the form layout styles and skip field formatting as per the form layout. kartik\form\ActiveField
$staticValue string The static value for the field to be displayed for the static input OR when the form is in staticOnly mode. kartik\form\ActiveField
$template string Inherits and overrides values from parent class. kartik\form\ActiveField
$validateOnBlur boolean|null Whether to perform validation when the input field loses focus. yii\widgets\ActiveField
$validateOnChange boolean|null Whether to perform validation when the value of the input field is changed. yii\widgets\ActiveField
$validateOnType boolean|null Whether to perform validation while the user is typing in the input field. yii\widgets\ActiveField
$validationDelay integer|null Number of milliseconds that the validation should be delayed when the user types in the field and $validateOnType is set true. yii\widgets\ActiveField
$wrapperOptions array Options for the wrapper tag, used in the {beginWrapper} token within $template. kartik\form\ActiveField

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_hasFeedback boolean Whether there is a feedback icon configuration set kartik\form\ActiveField
$_isHintSpecial boolean Whether there is a feedback icon configuration set kartik\form\ActiveField
$_isStatic boolean Is it a static input kartik\form\ActiveField
$_multiselect boolean The container for multi select kartik\form\ActiveField
$_offset boolean Whether the input is to be offset (like for checkbox or radio). kartik\form\ActiveField
$_pluginHintKeys array The list of hint keys that will be used by ActiveFieldHint jQuery plugin kartik\form\ActiveField
$_settings array The settings for the active field layout kartik\form\ActiveField

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. kartik\form\ActiveField
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__toString() PHP magic method that returns the string representation of this object. yii\widgets\ActiveField
__unset() Sets a component property to be null. yii\base\Component
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
begin() Renders the opening tag of the field container. kartik\form\ActiveField
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
checkbox() Renders a checkbox. This method will generate the "checked" tag attribute according to the model attribute value. kartik\form\ActiveField
checkboxButtonGroup() Renders a list of checkbox toggle buttons. kartik\form\ActiveField
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. kartik\form\ActiveField
className() Returns the fully qualified name of this class. yii\base\BaseObject
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
end() Renders the closing tag of the field container. kartik\form\ActiveField
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
error() Generates a tag that contains the first validation error of $attribute. yii\widgets\ActiveField
fileInput() Renders a file input. kartik\form\ActiveField
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
hiddenInput() Renders a hidden input. yii\widgets\ActiveField
hint() Renders the hint tag. kartik\form\ActiveField
init() Initializes the object. kartik\form\ActiveField
input() Renders an input tag. kartik\form\ActiveField
label() Generates a label tag for $attribute. kartik\form\ActiveField
listBox() Renders a list box. kartik\form\ActiveField
multiselect() Renders a multi select list box. This control extends the checkboxList and radioList available in yii\widgets\ActiveField - to display a scrolling multi select list box. kartik\form\ActiveField
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
passwordInput() Renders a password input. kartik\form\ActiveField
radio() Renders a radio button. This method will generate the "checked" tag attribute according to the model attribute value. kartik\form\ActiveField
radioButtonGroup() Renders a list of radio toggle buttons. kartik\form\ActiveField
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. kartik\form\ActiveField
render() Renders the whole field. kartik\form\ActiveField
staticInput() Renders a static input (display only). kartik\form\ActiveField
textInput() Renders a text input. kartik\form\ActiveField
textarea() Renders a text area. kartik\form\ActiveField
trigger() Triggers an event. yii\base\Component
widget() Renders a widget as the input of the field. kartik\form\ActiveField

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addAriaAttributes() Adds aria attributes to the input options. yii\widgets\ActiveField
addErrorClassBS4() Adds Bootstrap 4 validation class to the input options if needed. kartik\form\ActiveField
addErrorClassIfNeeded() Adds validation class to the input options if needed. yii\widgets\ActiveField
addRoleAttributes() Add role attributes to the input options yii\widgets\ActiveField
adjustLabelFor() Adjusts the for attribute for the label based on the input options. yii\widgets\ActiveField
buildLayoutParts() Builds the field layout parts kartik\form\ActiveField
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. kartik\form\ActiveField
createLayoutConfig() Create layout specific configuration kartik\form\ActiveField
generateAddon() Generates the addon markup kartik\form\ActiveField
generateHint() Generates the hint. kartik\form\ActiveField
getAddonContent() Parses and returns addon content. kartik\base\AddonTrait
getClientOptions() Returns the JS options for the field. yii\widgets\ActiveField
getColCss() Gets bootstrap grid column CSS based on size kartik\form\ActiveField
getConfigParam() Gets configuration parameter from formConfig kartik\form\ActiveField
getCustomCss() Gets custom CSS for custom controls supported in bootstrap 4.x and 5.x kartik\form\ActiveField
getFeedbackIcon() Generates a feedback icon kartik\form\ActiveField
getHintData() Gets a hint configuration setting value kartik\form\ActiveField
getHintIcon() Generates the hint icon kartik\form\ActiveField
getHintIconCss() Gets the hint icon css based on hintSettings kartik\form\ActiveField
getInputId() Returns the HTML id of the input element of this form field. yii\widgets\ActiveField
getToggleField() Generates a toggle field (checkbox or radio) kartik\form\ActiveField
getToggleFieldList() Renders a list of checkboxes / radio buttons. The selection of the checkbox / radio buttons is taken from the value of the model attribute. kartik\form\ActiveField
hasLabels() Validate label display status kartik\form\ActiveField
initActiveField() Initialize the active field kartik\form\ActiveField
initDisability() Validates and sets disabled or readonly inputs kartik\form\ActiveField
initFieldOptions() Initializes sizes and placeholder based on $autoPlaceholder kartik\form\ActiveField
initFieldSize() Initializes field by detecting the bootstrap CSS size and sets a size modifier CSS to the field container kartik\form\ActiveField
initHints() Initialize hint settings kartik\form\ActiveField
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: kartik\form\ActiveField
initLabels() Initialize label options kartik\form\ActiveField
initLayout() Initialize layout settings for label, input, error and hint blocks and for various bootstrap 3 form layouts kartik\form\ActiveField
isAjaxValidationEnabled() Checks if ajax validation enabled for the field. yii\widgets\ActiveField
isClientValidationEnabled() Checks if client validation enabled for the field. yii\widgets\ActiveField
isCustomControl() Checks whether bootstrap 4.x custom control based on options parameter kartik\form\ActiveField
mergeSettings() Merges the parameters for layout settings kartik\form\ActiveField
renderAddonItem() Renders an addon item based on its configuration kartik\base\AddonTrait
renderFeedbackIcon() Render the bootstrap feedback icon kartik\form\ActiveField
renderLabelParts() Render the label parts kartik\form\ActiveField
setHintData() Sets a hint property setting as a data attribute within self::$options kartik\form\ActiveField
setLayoutContainer() Sets the layout element container kartik\form\ActiveField

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
HINT_DEFAULT 1 kartik\form\ActiveField
HINT_SPECIAL 2 kartik\form\ActiveField
MULTI_SELECT_HEIGHT '145px' kartik\form\ActiveField
NOT_SET '' kartik\form\ActiveField
TYPE_CHECKBOX 'checkbox' kartik\form\ActiveField
TYPE_RADIO 'radio' kartik\form\ActiveField

Property Details

$_hasFeedback protected property

Whether there is a feedback icon configuration set

protected boolean $_hasFeedback false
$_isHintSpecial protected property

Whether there is a feedback icon configuration set

protected boolean $_isHintSpecial false
$_isStatic protected property

Is it a static input

protected boolean $_isStatic false
$_multiselect protected property

The container for multi select

protected boolean $_multiselect ''
$_offset protected property

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

protected boolean $_offset false
$_pluginHintKeys protected static property

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

protected static array $_pluginHintKeys = [
    'iconCssClass''labelCssClass''contentCssClass''hideOnEscape''hideOnClickOut''title''placement''container''animation''delay''template''selector''viewport'
]
$_settings protected property

The settings for the active field layout

protected array $_settings = [
    'input' => '{input}''error' => '{error}''hint' => '{hint}''showLabels' => true'showErrors' => true'labelSpan' => \kartik\form\ActiveForm::DEFAULT_LABEL_SPAN'deviceSize' => \kartik\form\ActiveForm::SIZE_MEDIUM
]
$addClass public property

CSS classname to add to the input

public string $addClass 'form-control'
$autoOffset public property

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.

public boolean $autoOffset true
$autoPlaceholder public property

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

public boolean $autoPlaceholder null
$checkEnclosedTemplate public property

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

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

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

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

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 property

Content to be placed after error block

$contentAfterField public property

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

$contentAfterHint public property

Content to be placed after hint block

$contentAfterInput public property

Content to be placed after input

$contentAfterLabel public property

Content to be placed after label

$contentBeforeError public property

Content to be placed before error block

$contentBeforeField public property

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

$contentBeforeHint public property

Content to be placed before hint block

$contentBeforeInput public property

Content to be placed before input

$contentBeforeLabel public property

Content to be placed before label

$customFileTemplate public property

The template for rendering the Bootstrap 4.x custom file browser control

See also https://getbootstrap.com/docs/4.1/components/forms/#file-browser.

public string $customFileTemplate "<div class=\"custom-file\">\n{input}\n{label}\n</div>\n{error}\n{hint}"
$deviceSize public property

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

public string $deviceSize null
$enableError public property

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

public boolean $enableError null
$enableLabel public property

Whether to render the label. Default is true.

public boolean $enableLabel null
$feedbackIcon public property

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).

See also http://getbootstrap.com/css/#with-optional-icons.

public array $feedbackIcon = []
$form public property
$highlightAddon public property

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

public boolean $highlightAddon true
$hintSettings public property

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].
public array $hintSettings = []
$hintType public property

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.

public integer $hintType self::HINT_DEFAULT
$horizontalCssClasses public property

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 kartik\form\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.
$labelOptions public property

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

public array $labelOptions = []
$labelSpan public property

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

public integer $labelSpan null
$renderEmptyWrapper public property

Whether to render the wrapper in the template if $wrapperOptions is empty.

$showErrors public property

Whether to show errors for the field

public boolean $showErrors null
$showHints public property

Whether to show hints for the field

public boolean $showHints null
$showLabels public property

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)
public boolean|string $showLabels null
$showRequiredIndicator public property

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 property

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

public boolean $skipFormLayout false
$staticValue public property

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.

public string $staticValue null
$template public property

Inherits and overrides values from parent class. The value can be overridden within kartik\form\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.
public string $template "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}"
$wrapperOptions public property

Options for the wrapper tag, used in the {beginWrapper} token within $template.

public array $wrapperOptions = []

Method Details

__construct() public method

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
public void __construct ( $config = [] )
$config array

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

addErrorClassBS4() protected method

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

protected void addErrorClassBS4 ( &$options )
$options array
throws Exception
begin() public method

Renders the opening tag of the field container.

public string begin ( )
return string

The rendering result.

buildLayoutParts() protected method

Builds the field layout parts

protected void buildLayoutParts ( $showLabels, $showErrors )
$showLabels boolean

Whether to show labels

$showErrors boolean

Whether to show errors

throws yii\base\InvalidConfigException
buildTemplate() protected method

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 void buildTemplate ( )
throws yii\base\InvalidConfigException
checkbox() public method

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

See also 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 yii\helpers\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 tag will be recognized which defaults to div. 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 yii\helpers\Html::encode(). If a value is null, the corresponding attribute will not be rendered.

public kartik\form\ActiveField checkbox ( $options = [], $enclosedByLabel null )
$options array

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 boolean|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.

return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
checkboxButtonGroup() public method

Renders a list of checkbox toggle buttons.

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

public kartik\form\ActiveField checkboxButtonGroup ( $items, $options = [] )
$items array

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

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.

return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
checkboxList() public method

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.

See also 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.

public kartik\form\ActiveField checkboxList ( $items, $options = [] )
$items array

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

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.
return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
createLayoutConfig() protected method

Create layout specific configuration

protected array createLayoutConfig ( $instanceConfig = [] )
$instanceConfig array

The configuration passed to this instance's constructor

return array

The layout specific default configuration for this instance

Renders a drop-down list.

The selection of the drop-down list is taken from the value of the model attribute.

public $this dropDownList ( $items, $options = [] )
$items array

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 array

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.

return $this

The field object itself.

throws yii\base\InvalidConfigException
end() public method

Renders the closing tag of the field container.

public string end ( )
return string

The rendering result.

fileInput() public method

Renders a file input.

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

public $this fileInput ( $options = [] )
$options array

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 yii\helpers\Html::encode().

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

return $this

The field object itself.

throws yii\base\InvalidConfigException
generateAddon() protected method

Generates the addon markup

protected string generateAddon ( )
throws \yii\base\InvalidConfigException|\Exception
generateHint() protected method

Generates the hint.

protected string generateHint ( $content null )
$content string

The hint content

getColCss() protected method

Gets bootstrap grid column CSS based on size

protected string getColCss ( $size )
$size string
throws \yii\base\InvalidConfigException|\Exception
getConfigParam() protected method

Gets configuration parameter from formConfig

protected string|boolean getConfigParam ( $param, $default true )
$param string

The parameter name

$default mixed

The default parameter value

return string|boolean

The parsed parameter value

throws Exception
getCustomCss() protected method

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

protected string getCustomCss ( $type )
$type string
throws Exception
getFeedbackIcon() protected method

Generates a feedback icon

protected string getFeedbackIcon ( $config, $cat, $type, $prefix, $id )
$config array

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

throws Exception
getHintData() protected method

Gets a hint configuration setting value

protected mixed getHintData ( $key, $default null )
$key string

The hint setting key to fetch

$default mixed

The default value if not set

throws Exception
getHintIcon() protected method

Generates the hint icon

protected string getHintIcon ( )
throws Exception
getHintIconCss() protected method

Gets the hint icon css based on hintSettings

protected array getHintIconCss ( $type )
$type string

Whether Label or Icon

return array

The css to be applied

getToggleField() protected method

Generates a toggle field (checkbox or radio)

protected kartik\form\ActiveField getToggleField ( $type self::TYPE_CHECKBOX, $options = [], $enclosedByLabel null )
$type string

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

$options array

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

$enclosedByLabel boolean|null

Whether the input is enclosed by the label tag

return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
getToggleFieldList() protected method

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

See also 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.

protected kartik\form\ActiveField getToggleFieldList ( $type, $items, $options = [], $asBtnGrp false )
$type string

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

$items array

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

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 boolean

Whether to generate the toggle list as a bootstrap button group

return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
hasLabels() protected method

Validate label display status

protected boolean|string hasLabels ( )
return boolean|string

Whether labels are to be shown

throws Exception
hint() public method

Renders the hint tag.

public $this hint ( $content, $options = [] )
$content string|boolean|null

The hint content. If null, the hint will be generated via yii\base\Model::getAttributeHint(). If false, the generated field will not contain the hint part. Note that this will NOT be encoded.

$options array

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 yii\helpers\Html::encode().

The following options are specially handled:

return $this

The field object itself.

init() public method

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )
throws yii\base\InvalidConfigException
initActiveField() protected method

Initialize the active field

protected void initActiveField ( )
throws yii\base\InvalidConfigException
initDisability() protected method

Validates and sets disabled or readonly inputs

protected void initDisability ( &$options )
$options array

The HTML attributes for the input

initFieldOptions() protected method

Initializes sizes and placeholder based on $autoPlaceholder

protected void initFieldOptions ( &$options )
$options array

The HTML attributes for the input

throws yii\base\InvalidConfigException
initFieldSize() protected method

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

protected void initFieldSize ( $options, $size )
$options array

The HTML options

$size string

The size to init

throws \yii\base\InvalidConfigException|\Exception
initHints() protected method

Initialize hint settings

protected void initHints ( )
throws \yii\base\InvalidConfigException|\Exception
initHorizontal() protected method

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:

  • 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'].
protected void initHorizontal ( )
throws yii\base\InvalidConfigException
initLabels() protected method

Initialize label options

protected void initLabels ( )
initLayout() protected method

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

protected void initLayout ( )
throws yii\base\InvalidConfigException
input() public method

Renders an input tag.

public $this input ( $type, $options = [] )
$type string

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

$options array

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 yii\helpers\Html::encode().

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

return $this

The field object itself.

throws yii\base\InvalidConfigException
isCustomControl() protected method

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

protected boolean isCustomControl ( &$options )
$options array

HTML attributes for the control

throws \yii\base\InvalidConfigException|\Exception
label() public method

Generates a label tag for $attribute.

public $this label ( $label null, $options = [] )
$label string|null|false

The label to use. If null, the label will be generated via yii\base\Model::getAttributeLabel(). If false, the generated field will not contain the label part. Note that this will NOT be encoded.

$options array|null

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 yii\helpers\Html::encode(). If a value is null, the corresponding attribute will not be rendered.

return $this

The field object itself.

listBox() public method

Renders a list box.

The selection of the list box is taken from the value of the model attribute.

public $this listBox ( $items, $options = [] )
$items array

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 array

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.

return $this

The field object itself.

throws yii\base\InvalidConfigException
mergeSettings() protected method

Merges the parameters for layout settings

protected void mergeSettings ( $showLabels, $showErrors )
$showLabels boolean

Whether to show labels

$showErrors boolean

Whether to show errors

multiselect() public method

Renders a multi select list box. This control extends the checkboxList and radioList available in yii\widgets\ActiveField - to display a scrolling multi select list box.

public kartik\form\ActiveField multiselect ( $items, $options = [] )
$items array

The data item used to generate the checkboxes or radio.

$options array

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
return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
passwordInput() public method

Renders a password input.

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

public $this passwordInput ( $options = [] )
$options array

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 yii\helpers\Html::encode().

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

return $this

The field object itself.

throws yii\base\InvalidConfigException
radio() public method

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

See also 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 yii\helpers\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 tag will be recognized which defaults to div. 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 yii\helpers\Html::encode(). If a value is null, the corresponding attribute will not be rendered.

public kartik\form\ActiveField radio ( $options = [], $enclosedByLabel null )
$options array

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 boolean|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.

return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
radioButtonGroup() public method

Renders a list of radio toggle buttons.

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

public kartik\form\ActiveField radioButtonGroup ( $items, $options = [] )
$items array

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

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.

return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
radioList() public method

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.

See also 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.

public kartik\form\ActiveField radioList ( $items, $options = [] )
$items array

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

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.
return kartik\form\ActiveField

Object

throws yii\base\InvalidConfigException
render() public method

Renders the whole field.

This method will generate the label, error tag, input tag and hint tag (if any), and assemble them into HTML according to $template.

public string render ( $content null )
$content string|callable|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;
}
return string

The rendering result.

throws yii\base\InvalidConfigException
renderFeedbackIcon() protected method

Render the bootstrap feedback icon

See also http://getbootstrap.com/css/#with-optional-icons.

protected string renderFeedbackIcon ( )
throws Exception
renderLabelParts() protected method

Render the label parts

protected void renderLabelParts ( $label null, $options = [] )
$label string|null

The label or null to use model label

$options array

The tag options

setHintData() protected method

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

protected void setHintData ( $key )
$key string

The hint property key

setLayoutContainer() protected method

Sets the layout element container

protected void setLayoutContainer ( $type, $css '', $chk true )
$type string

The layout element type

$css string

The css class for the container

$chk boolean

Whether to create the container for the layout element

staticInput() public method

Renders a static input (display only).

public kartik\form\ActiveField staticInput ( $options = [] )
$options array

The tag options in terms of name-value pairs.

return kartik\form\ActiveField

Object

throws Exception
textInput() public method

Renders a text input.

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

public $this textInput ( $options = [] )
$options array

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 yii\helpers\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.

return $this

The field object itself.

throws yii\base\InvalidConfigException
textarea() public method

Renders a text area.

The model attribute value will be used as the content in the textarea.

public $this textarea ( $options = [] )
$options array

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 yii\helpers\Html::encode().

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

return $this

The field object itself.

throws yii\base\InvalidConfigException
widget() public method

Renders a widget as the input of the field.

Note that the widget must have both model and attribute properties. They will be initialized with $model and $attribute of this field, respectively.

If you want to use a widget that does not have model and attribute properties, please use render() instead.

While widgets extending from kartik\base\Widget work with active field, it is preferred to use kartik\base\InputWidget as a base class.

For example to use the yii\widgets\MaskedInput widget to get some date input, you can use the following code, assuming that $form is your kartik\form\ActiveForm instance:

$form->field($model, 'date')->widget(\yii\widgets\MaskedInput::class, [
    'mask' => '99/99/9999',
]);

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

public $this widget ( $class, $config = [] )
$class string

The widget class name.

$config array

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

return $this

The field object itself.

throws Exception