Class kartik\form\ActiveField
Inheritance | kartik\form\ActiveField » yii\widgets\ActiveField |
---|---|
Available since version | 1.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
Property | Type | Description | Defined 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
Property | Type | Description | Defined 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
Protected Methods
Method | Description | Defined 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
Constant | Value | Description | Defined 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
Whether there is a feedback icon configuration set
Is it a static input
The container for multi select
Whether the input is to be offset (like for checkbox or radio).
The settings for the active field layout
CSS classname to add to the input
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
Whether the label is to be hidden and auto-displayed as a placeholder
Content to be placed after error block
Content to be placed after hint block
Content to be placed after input
Content to be placed after label
Content to be placed before error block
Content to be placed before hint block
Content to be placed before input
Content to be placed before label
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)
.
Whether to show errors for the field
Whether to show hints for the field
Whether to show labels for the field. Should be one of the following values:
true
: show labels for the fieldfalse
: hide labels for the fieldActiveForm::SCREEN_READER
: show in screen reader only (hide from normal display)
Whether to override the form layout styles and skip field formatting
as per the form layout. Defaults to false
.
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.
Method Details
public void begin ( ) |
Builds the field layout parts
protected void buildLayoutParts ( $showLabels, $showErrors ) | ||
$showLabels | bool | Whether to show labels |
$showErrors | bool | Whether to show errors |
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 ( ) |
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:
|
$enclosedByLabel | boolean | Whether to enclose the radio within the label. If |
return | kartik\form\ActiveField | Object |
---|
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:
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 |
---|
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:
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 |
Generates the addon markup
protected string generateAddon ( ) |
Generates the hint.
protected string generateHint ( $content = null ) | ||
$content | string | The hint content |
Parses and returns addon content
public static string getAddonContent ( $addon ) | ||
$addon | string|array | The addon parameter |
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 |
---|
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 |
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 |
---|
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:
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 |
---|
Validate label display status
protected bool|string hasLabels ( ) |
public void hint ( $content, $options = [] ) | ||
$content | ||
$options |
public void init ( ) |
Validates and sets disabled or readonly inputs
protected void initDisability ( <b>&</b>$options ) | ||
$options | array | The HTML attributes for the input |
Initialize label options
protected void initLabels ( ) |
Initialize layout settings for label, input, error and hint blocks and for various bootstrap 3 form layouts
protected void initLayout ( ) |
Initializes placeholder based on $autoPlaceholder
protected void initPlaceholder ( <b>&</b>$options ) | ||
$options | array | The HTML attributes for the input |
public void input ( $type, $options = [] ) | ||
$type | ||
$options |
public void listBox ( $items, $options = [] ) | ||
$items | ||
$options |
Merges the parameters for layout settings
protected void mergeSettings ( $showLabels, $showErrors ) | ||
$showLabels | bool | Whether to show labels |
$showErrors | bool | Whether to show errors |
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
|
return | kartik\form\ActiveField | Object |
---|
public void passwordInput ( $options = [] ) | ||
$options |
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:
|
$enclosedByLabel | boolean | Whether to enclose the radio within the label. If |
return | kartik\form\ActiveField | Object |
---|
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:
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 |
---|
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:
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 |
---|
public void render ( $content = null ) | ||
$content |
Renders the bootstrap feedback icon.
protected string renderFeedbackIcon ( ) |
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 |
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 |
---|
public void textInput ( $options = [] ) | ||
$options |
public void textarea ( $options = [] ) | ||
$options |
public void widget ( $class, $config = [] ) | ||
$class | ||
$config |