Class kartik\builder\BaseForm

Inheritancekartik\builder\BaseForm » kartik\base\Widget » yii\base\Widget » yii\base\Component » yii\base\BaseObject
Implementskartik\base\BootstrapInterface, yii\base\Configurable, yii\base\ViewContextInterface
Uses Traitskartik\base\BootstrapTrait, kartik\base\TranslationTrait, kartik\base\WidgetTrait, kartik\builder\FormTrait
Subclasseskartik\builder\Form, kartik\builder\TabularForm
Available since version1.0

BaseForm is the base class for the kartik\builder\Form and kartik\builder\TabularForm builder widgets in this extension.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$attributeDefaults array The default settings that will be applied for all attributes. kartik\builder\BaseForm
$attributes array The attribute settings. kartik\builder\BaseForm
$autoIdPrefix string The prefix to the automatically generated widget IDs. yii\base\Widget
$baseSourcePath string|false Get parsed base source path based on $sourcePath setting. If $sourcePath is not set, it will return the current working directory of this widget class. kartik\base\WidgetTrait
$behaviors yii\base\Behavior[] List of behaviors attached to this component. yii\base\Component
$bsColCssPrefixes array The bootstrap grid column css prefixes mapping, the key is the bootstrap versions, and the value is an array containing the sizes and their corresponding grid column css prefixes. kartik\base\BootstrapTrait
$bsCssMap array CSS conversion mappings across bootstrap library versions. kartik\base\BootstrapTrait
$bsExtBasename integer The yii2 bootstrap extension base name (readonly property available via getter method getBsExtBasename()) kartik\base\BootstrapTrait
$bsVer integer Bootstrap version number currently set (readonly property available via getter method getBsVer()) kartik\base\BootstrapTrait
$bsVersion integer|string The bootstrap library version that you wish to use for this specific extension / widget. kartik\base\BootstrapTrait
$counter integer A counter used to generate $id for widgets. yii\base\Widget
$defaultBtnCss string Default bootstrap button CSS (readonly property available via getter method getDefaultBtnCss()) kartik\base\BootstrapTrait
$defaultIconPrefix string Default icon prefix (readonly property available via getter method getDefaultIconPrefix()) kartik\base\BootstrapTrait
$defaultOptions array Default HTML attributes or other settings for widgets. kartik\base\WidgetTrait
$defaultPluginOptions array Default plugin options for the widget kartik\base\WidgetTrait
$dropdownClass string Bootstrap dropdown class name based on currently configured bootstrap version (readonly property available via getter method getDropdownClass()) kartik\base\BootstrapTrait
$form kartik\form\ActiveForm The form instance. kartik\builder\BaseForm
$formName string The form name to be provided if not using with model and kartik\form\ActiveForm. kartik\builder\BaseForm
$hashVarLoadPosition integer The position where the client JS hash variables for the input widget will be loaded. kartik\base\WidgetTrait
$i18n array The the internalization configuration for this widget. kartik\base\TranslationTrait
$id string|null ID of the widget. Note that the type of this property differs in getter and setter. See getId() and setId() for details. yii\base\Widget
$moduleId string The module identifier if this widget is part of a module. kartik\base\WidgetTrait
$options array HTML attributes or other settings for widgets. kartik\base\Widget
$pjaxContainerId string The identifier for the PJAX widget container if the widget is to be rendered inside a PJAX container. kartik\base\WidgetTrait
$pjaxDuplicationFix boolean Prevent duplication of pjax containers when browser back & forward buttons are pressed. kartik\base\WidgetTrait
$pluginDestroyJs string The javascript that will be used to destroy the jQuery plugin kartik\base\WidgetTrait
$pluginEvents array Widget JQuery events. kartik\base\WidgetTrait
$pluginName string The plugin name kartik\base\WidgetTrait
$pluginOptions array Widget plugin options. kartik\base\WidgetTrait
$sourcePath string Directory path to the original widget source. kartik\base\WidgetTrait
$stack yii\base\Widget[] The widgets that are currently being rendered (not ended). yii\base\Widget
$staticOnly boolean Whether all inputs in the form are to be static only kartik\builder\BaseForm
$view yii\web\View The view object that can be used to render views or view files. Note that the type of this property differs in getter and setter. See getView() and setView() for details. yii\base\Widget
$viewPath string The directory containing the view files for this widget. yii\base\Widget

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_basicInputs array The basic inputs kartik\builder\BaseForm
$_bsVer integer Current bootstrap version number kartik\base\BootstrapTrait
$_dataVar string The HTML5 data variable name that will be used to store the Json encoded pluginOptions within the element on which the jQuery plugin will be initialized. kartik\base\WidgetTrait
$_defaultBtnCss string Default bootstrap button CSS kartik\base\BootstrapTrait
$_defaultIconPrefix string Default icon CSS prefix kartik\base\BootstrapTrait
$_dropdownInputs array The dropdown inputs kartik\builder\BaseForm
$_encOptions string The JSON encoded plugin options. kartik\base\WidgetTrait
$_hashVar string The generated hashed variable name that will store the JSON encoded pluginOptions in yii\web\View::POS_HEAD. kartik\base\WidgetTrait
$_isBs4 boolean Flag to detect whether bootstrap 4. kartik\base\BootstrapTrait
$_msgCat string Translation message file category name for i18n. kartik\base\TranslationTrait
$_validInputs array The allowed valid list of input types kartik\builder\BaseForm

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. yii\base\BaseObject
__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
__unset() Sets a component property to be null. yii\base\Component
addCssClass() Adds bootstrap CSS class to options by parsing the bootstrap version for the specified Bootstrap CSS type. kartik\base\BootstrapTrait
afterRun() This method is invoked right after a widget is executed. yii\base\Widget
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
beforeRun() This method is invoked right before the widget is executed. yii\base\Widget
begin() Begins a widget. yii\base\Widget
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
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() Ends a widget. yii\base\Widget
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBSClass() Gets the respective Bootstrap class based on currently configured bootstrap version. kartik\base\BootstrapTrait
getBaseSourcePath() Get parsed base source path based on $sourcePath setting. If $sourcePath is not set, it will return the current working directory of this widget class. kartik\base\WidgetTrait
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getBsVer() Gets the current set bootstrap version number. kartik\base\BootstrapTrait
getCssClass() Gets bootstrap css class by parsing the bootstrap version for the specified BS CSS type. kartik\base\BootstrapTrait
getDefaultBtnCss() Gets the default button CSS kartik\base\BootstrapTrait
getDefaultIconPrefix() Gets the default icon css prefix kartik\base\BootstrapTrait
getDropdownClass() Gets the respective bootstrap dropdown class name based on currently configured bootstrap version. kartik\base\BootstrapTrait
getId() Returns the ID of the widget. yii\base\Widget
getView() kartik\base\WidgetTrait
getViewPath() Returns the directory containing the view files for this widget. yii\base\Widget
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
init() Initializes the object. kartik\builder\BaseForm
initI18N() Yii i18n messages configuration for generating translations kartik\base\TranslationTrait
isBs() Validate Bootstrap version kartik\base\BootstrapTrait
isBs4() Validate if Bootstrap 4.x version. kartik\base\BootstrapTrait
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
registerWidgetJs() Registers a JS code block for the widget. kartik\base\WidgetTrait
removeCssClass() Removes bootstrap CSS class from options by parsing the bootstrap version for the specified Bootstrap CSS type. kartik\base\BootstrapTrait
render() Renders a view. yii\base\Widget
renderFile() Renders a view file. yii\base\Widget
run() Executes the widget. yii\base\Widget
setId() Sets the ID of the widget. yii\base\Widget
setView() Sets the view object to be used by this widget. yii\base\Widget
trigger() Triggers an event. yii\base\Component
widget() Creates a widget instance and runs it. yii\base\Widget

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addAsset() Adds an asset to the view. kartik\base\WidgetTrait
checkBaseConfig() Checks base configuration and throws a configuration exception if invalid. kartik\builder\FormTrait
checkFormConfig() Checks the form configuration and throws a configuration exception if invalid. kartik\builder\FormTrait
configureBsVersion() Configures the bootstrap version settings kartik\base\BootstrapTrait
fixPjaxDuplication() Fix for weird PJAX container duplication behavior on pressing browser back and forward buttons. kartik\base\WidgetTrait
getBsExtBasename() The yii2-bootstrap extension base name. kartik\base\BootstrapTrait
getInput() Generates the active field input by parsing the label and hint. kartik\builder\BaseForm
getPluginScript() Returns the plugin registration script. kartik\base\WidgetTrait
hasModel() Check if a valid model is set for the object instance. kartik\builder\FormTrait
hashPluginOptions() Generates a hashed variable to store the pluginOptions. kartik\base\WidgetTrait
initBsVersion() Initializes bootstrap versions for the widgets and asset bundles. kartik\base\BootstrapTrait
initDestroyJs() Generates the pluginDestroyJs script if it is not set. kartik\base\WidgetTrait
isSameVersion() Compares two versions and checks if they are of the same major BS version. kartik\base\BootstrapTrait
mergeDefaultOptions() Merge default options kartik\base\WidgetTrait
parseVer() Parses and returns the major BS version kartik\base\BootstrapTrait
prepareAttributes() Prepares attributes based on visibility setting kartik\builder\BaseForm
registerPlugin() Registers a specific plugin and the related events kartik\base\WidgetTrait
registerPluginOptions() Registers plugin options by storing within a uniquely generated javascript variable. kartik\base\WidgetTrait
renderActiveInput() Renders active input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set. kartik\builder\BaseForm
renderInput() Renders normal form input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set. kartik\builder\BaseForm
renderRawActiveInput() Renders raw active input based on the attribute settings. kartik\builder\BaseForm
renderRawInput() Renders raw form input based on the attribute settings. kartik\builder\BaseForm
setDataVar() Sets a HTML5 data variable. kartik\base\WidgetTrait

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_AFTER_RUN yii\base\WidgetEvent An event raised right after executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_BEFORE_RUN yii\base\WidgetEvent An event raised right before executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_INIT yii\base\Event An event that is triggered when the widget is initialized via init(). (available since version 2.0.11) yii\base\Widget

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
INPUT_CHECKBOX 'checkbox' kartik\builder\BaseForm
INPUT_CHECKBOX_BUTTON_GROUP 'checkboxButtonGroup' kartik\builder\BaseForm
INPUT_CHECKBOX_LIST 'checkboxList' kartik\builder\BaseForm
INPUT_DROPDOWN_LIST 'dropdownList' kartik\builder\BaseForm
INPUT_FILE 'fileInput' kartik\builder\BaseForm
INPUT_HIDDEN 'hiddenInput' kartik\builder\BaseForm
INPUT_HIDDEN_STATIC 'hiddenStaticInput' kartik\builder\BaseForm
INPUT_HTML5 'input' kartik\builder\BaseForm
INPUT_LIST_BOX 'listBox' kartik\builder\BaseForm
INPUT_MULTISELECT 'multiselect' kartik\builder\BaseForm
INPUT_PASSWORD 'passwordInput' kartik\builder\BaseForm
INPUT_RADIO 'radio' kartik\builder\BaseForm
INPUT_RADIO_BUTTON_GROUP 'radioButtonGroup' kartik\builder\BaseForm
INPUT_RADIO_LIST 'radioList' kartik\builder\BaseForm
INPUT_RAW 'raw' kartik\builder\BaseForm
INPUT_STATIC 'staticInput' kartik\builder\BaseForm
INPUT_TEXT 'textInput' kartik\builder\BaseForm
INPUT_TEXTAREA 'textarea' kartik\builder\BaseForm
INPUT_WIDGET 'widget' kartik\builder\BaseForm

Property Details

$_basicInputs protected static property

The basic inputs

protected static array $_basicInputs = [
    self::INPUT_TEXT => true,
    
self::INPUT_PASSWORD => true,
    
self::INPUT_TEXTAREA => true,
    
self::INPUT_FILE => true,
    
self::INPUT_HIDDEN => true,
    
self::INPUT_STATIC => true
]
$_dropdownInputs protected static property

The dropdown inputs

protected static array $_dropdownInputs = [
    self::INPUT_DROPDOWN_LIST => true,
    
self::INPUT_LIST_BOX => true,
    
self::INPUT_CHECKBOX_LIST => true,
    
self::INPUT_RADIO_LIST => true,
    
self::INPUT_CHECKBOX_BUTTON_GROUP => true,
    
self::INPUT_RADIO_BUTTON_GROUP => true,
    
self::INPUT_MULTISELECT => true
]
$_validInputs protected static property

The allowed valid list of input types

protected static array $_validInputs = [
    self::INPUT_TEXT,
    
self::INPUT_TEXTAREA,
    
self::INPUT_PASSWORD,
    
self::INPUT_DROPDOWN_LIST,
    
self::INPUT_LIST_BOX,
    
self::INPUT_CHECKBOX,
    
self::INPUT_RADIO,
    
self::INPUT_CHECKBOX_LIST,
    
self::INPUT_RADIO_LIST,
    
self::INPUT_CHECKBOX_BUTTON_GROUP,
    
self::INPUT_RADIO_BUTTON_GROUP,
    
self::INPUT_MULTISELECT,
    
self::INPUT_STATIC,
    
self::INPUT_HIDDEN,
    
self::INPUT_HIDDEN_STATIC,
    
self::INPUT_FILE,
    
self::INPUT_HTML5,
    
self::INPUT_WIDGET,
    
self::INPUT_RAW
]
$attributeDefaults public property

The default settings that will be applied for all attributes. The array will be configured similar to a single attribute setting value in the $attributes array. One will typically default markup and styling like type, container, prepend, append etc. The settings at the $attributes level will override these default settings.

$attributes public property

The attribute settings. This is an associative array, which needs to be setup as $attribute_name => $attribute_settings, where:

  • attribute_name: string, the name of the attribute
  • attribute_settings: array, the settings for the attribute, where you can set the following:
    • 'type': string, the input type for the attribute. Should be one of the INPUT_ constants. Defaults to INPUT_TEXT.
    • 'visible': boolean, whether the attribute is visible. One can use this property to control visibility of attributes conditionally.
    • 'attributes': array, the nested group of sub attributes that will be grouped together, this configuration will be similar to the parent attributes. The label property will be auto set to false for each sub attribute.
    • 'value': string|Closure, the value to be displayed if the type is set to INPUT_RAW or INPUT_STATIC. This will display the raw text from value field if it is a string. If this is a Closure, your anonymous function call should be of the type: function ($model, $key, $index, $widget) { }, where $model is the current model, $key is the key associated with the data model $index is the zero based index of the dataProvider, and $widget is the current widget instance.
    • 'staticValue': string|Closure, the value to be displayed for INPUT_STATIC. If not set, the value will be automatically generated from the value setting above OR from the value of the model attribute. If this is setup as a Closure, your anonymous function call should be of the type: function ($model, $key, $index, $widget) { }, where $model is the current model, $key is the key associated with the data model, $index is the zero based index of the dataProvider, and $widget is the current widget instance.
    • 'format': string|array, applicable only for INPUT_STATIC type (and only in tabular forms). This controls which format should the value of each data model be displayed as (e.g. "raw", "text", "html", ['date', 'php:Y-m-d']). Supported formats are determined by [Yii::$app->formatter]. Default format is "raw".
    • 'hiddenStaticOptions': array, HTML attributes for the static control container and applicable only for INPUT_HIDDEN_STATIC type.
    • 'label': string, (optional) the custom attribute label. If this is not set, the model attribute label will be automatically used. If you set it to false, the label will be entirely hidden.
    • 'labelSpan': int, the grid span width of the label container, which is especially useful for horizontal forms. If not set this will be derived automatically from the formConfig['labelSpan'] property of $form (ActiveForm).
    • 'labelOptions': array, (optional) the HTML attributes for the label. Will be applied only when NOT using with active form and only if label is set.
    • 'prepend': string, (optional) any markup to prepend before the input. For ActiveForm fields, this content will be prepended before the field group (including label, input, error, hint blocks).
    • 'append': string, (optional) any markup to append before the input. For ActiveForm fields, this content will be appended after the field group (including label, input, error, hint blocks).
    • 'container': array, (optional) HTML attributes for the div container to wrap the input. For ActiveForm, this will envelop the field group (including label, input, error, hint blocks). If not set or empty, no container will be wrapped.
    • 'inputContainer': array, (optional) HTML attributes for the div container to wrap the input control only. If not set or empty, no container will be wrapped. Will be applied only when NOT using with ActiveForm.
    • 'fieldConfig': array, the configuration for the active field.
    • hint: string, the hint text to be shown below the active field.
    • 'items': array, the list of items if input type is one of the following: INPUT_DROPDOWN_LIST, INPUT_LIST_BOX, INPUT_CHECKBOX_LIST, INPUT_RADIO_LIST, INPUT_MULTISELECT INPUT_CHECKBOX_BUTTON_GROUP, INPUT_RADIO_BUTTON_GROUP
    • enclosedByLabel: bool, if the INPUT_CHECKBOX or INPUT_RADIO is to be enclosed by label. Defaults to true.
    • html5type: string, the type of HTML5 input, if input type is set to INPUT_HTML5.
    • 'widgetClass': string, the classname if input type is INPUT_WIDGET.
    • 'options': array, the HTML attributes or widget settings to be applied to the input.
    • 'columnOptions': array, for a Form, it will override columnOptions setup at Form level. For a TabularForm it will allow you to append additional column options for the grid data column.
public array $attributes = []
$form public property

The form instance.

$formName public property

The form name to be provided if not using with model and kartik\form\ActiveForm.

public string $formName null
$staticOnly public property

Whether all inputs in the form are to be static only

public boolean $staticOnly false

Method Details

getInput() protected static method

Generates the active field input by parsing the label and hint.

protected static kartik\form\ActiveField getInput ( $field, $label null, $hint null )
$field kartik\form\ActiveField

The active field instance.

$label string

The label for the field

$hint string

The hint for the field

init() public method

Initializes the object.

This method is called at the end of the constructor. The default implementation will trigger an EVENT_INIT event.

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

Prepares attributes based on visibility setting

protected static void prepareAttributes ( &$attributes = [] )
$attributes array

The attributes to be prepared

throws Exception
renderActiveInput() protected method

Renders active input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set.

protected string renderActiveInput ( $form, $model, $attribute, $settings )
$form kartik\form\ActiveForm

The form instance.

$model yii\base\Model

The data model.

$attribute string

The name of the attribute.

$settings array

The attribute settings.

throws yii\base\InvalidConfigException
renderInput() protected method

Renders normal form input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set.

protected string renderInput ( $attribute, $settings = [] )
$attribute string

The name of the attribute.

$settings array

The attribute settings.

return string

The form input markup.

throws yii\base\InvalidConfigException
renderRawActiveInput() protected method

Renders raw active input based on the attribute settings.

protected string renderRawActiveInput ( $form, $model, $attribute, $settings )
$form kartik\form\ActiveForm

The form instance.

$model yii\base\Model

The data model.

$attribute string

The name of the attribute.

$settings array

The attribute settings.

return string

The generated active input.

throws yii\base\InvalidConfigException
renderRawInput() protected method

Renders raw form input based on the attribute settings.

protected string renderRawInput ( $attribute, &$id, $settings = [] )
$attribute string

The name of the attribute.

$id string

The input identifier.

$settings array

The attribute settings.

return string

The form input markup.

throws yii\base\InvalidConfigException
throws Exception