Class kartik\form\ActiveField

Inheritancekartik\form\ActiveField » yii\widgets\ActiveField
Available since version1.0

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

Example(s): `php 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']]);

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$addClass string CSS classname to add to the input kartik\form\ActiveField
$addon array Addon options for text and password inputs. kartik\form\ActiveField
$autoPlaceholder boolean Whether the label is to be hidden and auto-displayed as a placeholder kartik\form\ActiveField
$contentAfterError string Content to be placed after error block 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
$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
$feedbackIcon array The feedback icon configuration (applicable for bootstrap text inputs). kartik\form\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
$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

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_hasFeedback bool 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
$_settings array The settings for the active field layout kartik\form\ActiveField

Public Methods

Hide inherited methods

MethodDescriptionDefined By
begin() kartik\form\ActiveField
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. kartik\form\ActiveField
getAddonContent() Parses and returns addon content kartik\form\ActiveField
hint() kartik\form\ActiveField
init() kartik\form\ActiveField
input() kartik\form\ActiveField
listBox() 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
passwordInput() kartik\form\ActiveField
radio() Renders a radio button. kartik\form\ActiveField
radioButtonGroup() Renders a list of radio toggle buttons. kartik\form\ActiveField
radioList() Renders a list of radio buttons. kartik\form\ActiveField
render() kartik\form\ActiveField
staticInput() Renders a static input (display only). kartik\form\ActiveField
textInput() kartik\form\ActiveField
textarea() kartik\form\ActiveField
widget() kartik\form\ActiveField

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
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
generateAddon() Generates the addon markup kartik\form\ActiveField
generateHint() Generates the hint. kartik\form\ActiveField
getConfigParam() Gets configuration parameter from formConfig kartik\form\ActiveField
getFeedbackIcon() Generates a feedback icon kartik\form\ActiveField
getToggleField() Generates a toggle field (checkbox or radio) kartik\form\ActiveField
getToggleFieldList() Renders a list of checkboxes / radio buttons. kartik\form\ActiveField
hasLabels() Validate label display status kartik\form\ActiveField
initDisability() Validates and sets disabled or readonly inputs 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
initPlaceholder() Initializes placeholder based on $autoPlaceholder kartik\form\ActiveField
mergeSettings() Merges the parameters for layout settings kartik\form\ActiveField
renderFeedbackIcon() Renders the bootstrap feedback icon. kartik\form\ActiveField
setLayoutContainer() Sets the layout element container kartik\form\ActiveField

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
MULTI_SELECT_HEIGHT '145px' kartik\form\ActiveField
STYLE_INLINE 'inline' 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 bool $_hasFeedback 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
$_settings protected property

The settings for the active field layout

protected array $_settings = ['input' => '{input}''error' => '{error}''hint' => '{hint}''showLabels' => true'showErrors' => true]
$addClass public property

CSS classname to add to the input

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

Addon options for text and password inputs. The following settings can be configured:

  • prepend: array the prepend addon configuration
  • content: string the prepend addon content
  • asButton: boolean whether the addon is a button or button group. Defaults to false.
  • options: array the HTML attributes to be added to the container.
  • append: array the append addon configuration
  • content: string/array the append addon content
  • asButton: boolean whether the addon is a button or button group. Defaults to false.
  • options: array the HTML attributes to be added to the container.
  • groupOptions: array HTML options for the input group
  • contentBefore: string content placed before addon
  • contentAfter: string content placed after addon
public array $addon = []
$autoPlaceholder public property

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

public boolean $autoPlaceholder null
$contentAfterError public property

Content to be placed after error block

$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

$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

$feedbackIcon public property

The feedback icon configuration (applicable for bootstrap text inputs).

See also http://getbootstrap.com/css/#with-optional-icons 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-. - 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).

public array $feedbackIcon = []
$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
$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

Method Details

begin() public method

public void begin ( )
buildLayoutParts() protected method

Builds the field layout parts

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

Whether to show labels

$showErrors bool

Whether to show errors

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 ( )
checkbox() public method

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

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

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

  • 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.
$enclosedByLabel boolean

Whether to enclose the radio within the label. If true, the method will still use \kartik\form\template to layout the checkbox and the error message except that the radio is enclosed by the label tag.

return kartik\form\ActiveField

Object

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

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.

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.

$options array

Options (name => config) for the checkbox 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.
  • 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 kartik\form\ActiveField

Object

public void dropDownList ( $items, $options = [] )
$items
$options
generateAddon() protected method

Generates the addon markup

protected string generateAddon ( )
generateHint() protected method

Generates the hint.

protected string generateHint ( $content null )
$content string

The hint content

getAddonContent() public static method

Parses and returns addon content

public static string getAddonContent ( $addon )
$addon string|array

The addon parameter

getConfigParam() protected method

Gets configuration parameter from formConfig

protected \kartik\form\the getConfigParam ( $param, $default true )
$param string

The parameter name

$default mixed

The default parameter value

return \kartik\form\the

Parsed parameter value

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

getToggleField() protected method

Generates a toggle field (checkbox or radio)

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

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

$options array

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

$enclosedByLabel
return kartik\form\ActiveField

Object

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.

protected kartik\form\ActiveField getToggleFieldList ( $type, $items, $options = [], $asButtonGroup 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.

$options array

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

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

$asButtonGroup bool

Whether to generate the toggle list as a bootstrap button group

return kartik\form\ActiveField

Object

hasLabels() protected method

Validate label display status

protected bool|string hasLabels ( )
hint() public method

public void hint ( $content, $options = [] )
$content
$options
init() public method

public void init ( )
initDisability() protected method

Validates and sets disabled or readonly inputs

protected void initDisability ( <b>&</b>$options )
$options array

The HTML attributes for the input

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 ( )
initPlaceholder() protected method

Initializes placeholder based on $autoPlaceholder

protected void initPlaceholder ( <b>&</b>$options )
$options array

The HTML attributes for the input

input() public method

public void input ( $type, $options = [] )
$type
$options
listBox() public method

public void listBox ( $items, $options = [] )
$items
$options
mergeSettings() protected method

Merges the parameters for layout settings

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

Whether to show labels

$showErrors bool

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 self::TYPE_RADIO or self::TYPE_CHECKBOX
return kartik\form\ActiveField

Object

passwordInput() public method

public void passwordInput ( $options = [] )
$options
radio() public method

Renders a radio button.

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

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

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

  • 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.
$enclosedByLabel boolean

Whether to enclose the radio within the label. If true, the method will still use \kartik\form\template to layout the checkbox and the error message except that the radio is enclosed by the label tag.

return kartik\form\ActiveField

Object

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.

$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

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.

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:

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

Object

render() public method

public void render ( $content null )
$content
renderFeedbackIcon() protected method

Renders the bootstrap feedback icon.

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

protected string renderFeedbackIcon ( )
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 bool

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

textInput() public method

public void textInput ( $options = [] )
$options
textarea() public method

public void textarea ( $options = [] )
$options
widget() public method

public void widget ( $class, $config = [] )
$class
$config