Class kartik\base\InputWidget

Inheritancekartik\base\InputWidget » yii\widgets\InputWidget
Uses Traitskartik\base\TranslationTrait, kartik\base\WidgetTrait
Subclasseskartik\base\Html5Input, kartik\select2\Select2
Available since version1.0

InputWidget is the base class for widgets extending the \yii\widgets\InputWidget that collect user inputs in all Krajee input extensions.

An input widget can be associated with a data model and an attribute, or a name and a value. If the former, the name and the value will be generated automatically.

Classes extending from this widget can be used in an \yii\widgets\ActiveForm using the \yii\widgets\ActiveField::widget() method. For example like this:

<?= $form->field($model, 'from_date')->widget('WidgetClassName', [
    // configure additional widget properties here
]) ?>

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$convertFormat boolean Whether the widget should automatically format the date from the PHP DateTime format to the javascript/jquery plugin format. kartik\base\InputWidget
$data array The data (for list inputs) kartik\base\InputWidget
$disabled boolean Whether input is to be disabled kartik\base\InputWidget
$enablePopStateFix boolean Enable pop state fix for pjax container on press of browser back & forward buttons. kartik\base\InputWidget
$i18n array The the internalization configuration for this widget. kartik\base\InputWidget
$language string The language configuration (e.g. 'fr-FR', 'zh-CN'). kartik\base\InputWidget
$pjaxContainerId string A pjax container identifier if applicable inside which the widget will be rendered. kartik\base\InputWidget
$pluginDestroyJs string The javascript that will be used to destroy the jQuery plugin kartik\base\InputWidget
$pluginEvents array Widget JQuery events. kartik\base\InputWidget
$pluginLoading boolean Show loading indicator while plugin loads kartik\base\InputWidget
$pluginName string The name of the jQuery plugin. kartik\base\InputWidget
$pluginOptions array Widget plugin options. kartik\base\InputWidget
$readonly boolean Whether input is to be readonly kartik\base\InputWidget

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_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\InputWidget
$_encOptions string The JSON encoded plugin options. kartik\base\InputWidget
$_hashVar string The generated hashed variable name that will store the JSON encoded pluginOptions in \kartik\base\View::POS_HEAD. kartik\base\InputWidget
$_lang string The two or three letter lowercase code for the language according to ISO-639. kartik\base\InputWidget
$_langFile string The language js file. kartik\base\InputWidget
$_loadIndicator string The indicator to be displayed while plugin is loading. kartik\base\InputWidget
$_msgCat string Translation message file category name for i18n. kartik\base\InputWidget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
init() kartik\base\InputWidget
initI18N() Yii i18n messages configuration for generating translations kartik\base\TranslationTrait
registerWidgetJs() Registers a JS code block for the widget. kartik\base\WidgetTrait

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addAsset() Adds an asset to the view. kartik\base\WidgetTrait
convertDateFormat() Automatically convert the date format from PHP DateTime to Javascript DateTime format kartik\base\InputWidget
getInput() Generates an input. kartik\base\InputWidget
getPluginScript() Returns the plugin registration script. kartik\base\WidgetTrait
hashPluginOptions() Generates a hashed variable to store the pluginOptions. The following special data attributes will also be setup for the input widget, that can be accessed through javascript : kartik\base\WidgetTrait
initDestroyJs() Generates the pluginDestroyJs script if it is not set. kartik\base\WidgetTrait
initDisability() Validates and sets disabled or readonly inputs. kartik\base\InputWidget
initInputWidget() Initializes the input widget. kartik\base\InputWidget
initLanguage() Initialize the plugin language. kartik\base\InputWidget
parseDateFormat() Parses and sets plugin date format based on attribute type using \yii\helpers\FormatConverter. Currently this method is used only within the \kartik\date\DatePicker and \kartik\datetime\DateTimePicker\ widgets. kartik\base\InputWidget
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
setDataVar() Sets a HTML5 data variable. kartik\base\WidgetTrait
setLanguage() Sets the language JS file if it exists. kartik\base\InputWidget

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
LOAD_PROGRESS '
 
'
kartik\base\InputWidget

Property Details

$_dataVar protected property

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.

protected string $_dataVar null
$_encOptions protected property

The JSON encoded plugin options.

protected string $_encOptions ''
$_hashVar protected property

The generated hashed variable name that will store the JSON encoded pluginOptions in \kartik\base\View::POS_HEAD.

protected string $_hashVar null
$_lang protected property

The two or three letter lowercase code for the language according to ISO-639.

protected string $_lang ''
$_langFile protected property

The language js file.

protected string $_langFile ''
$_loadIndicator protected property

The indicator to be displayed while plugin is loading.

protected string $_loadIndicator ''
$_msgCat protected property

Translation message file category name for i18n.

See also [[\yii\i18n\I18N]].

protected string $_msgCat ''
$convertFormat public property

Whether the widget should automatically format the date from the PHP DateTime format to the javascript/jquery plugin format. This is more applicable for widgets that manage date / time inputs.

See also http://php.net/manual/en/function.date.php.

public boolean $convertFormat false
$data public property

The data (for list inputs)

public array $data = []
$disabled public property

Whether input is to be disabled

public boolean $disabled false
$enablePopStateFix public property

Enable pop state fix for pjax container on press of browser back & forward buttons.

$i18n public property

The the internalization configuration for this widget.

See also [[\yii\i18n\I18N]] component for understanding the configuration details.

public array $i18n = []
$language public property

The language configuration (e.g. 'fr-FR', 'zh-CN'). The format for the language/locale is ll-CC where ll is a two or three letter lowercase code for a language according to ISO-639 and CC is the country code according to ISO-3166. If this property not set, then the current application language will be used.

public string $language null
$pjaxContainerId public property

A pjax container identifier if applicable inside which the widget will be rendered. If this is set, the widget will automatically reinitialize on pjax render completion.

public string $pjaxContainerId null
$pluginDestroyJs public property

The javascript that will be used to destroy the jQuery plugin

public string $pluginDestroyJs null
$pluginEvents public property

Widget JQuery events. You must define events in event-name => event-function format. For example:

pluginEvents = [
    'change' => 'function() { log("change"); }',
    'open' => 'function() { log("open"); }',
];
public array $pluginEvents = []
$pluginLoading public property

Show loading indicator while plugin loads

public boolean $pluginLoading true
$pluginName public property

The name of the jQuery plugin.

public string $pluginName ''
$pluginOptions public property

Widget plugin options.

public array $pluginOptions = []
$readonly public property

Whether input is to be readonly

public boolean $readonly false

Method Details

convertDateFormat() protected static method

Automatically convert the date format from PHP DateTime to Javascript DateTime format

See also:

protected static string convertDateFormat ( $format )
$format string

The PHP date format string

getInput() protected method

Generates an input.

protected string getInput ( $type, $list false )
$type string

The input type

$list boolean

Whether the input is of dropdown list type

return string

The rendered input markup

init() public method

public void init ( )
initDisability() protected method

Validates and sets disabled or readonly inputs.

protected void initDisability ( &$options )
$options array

The HTML attributes for the input

initInputWidget() protected method

Initializes the input widget.

protected void initInputWidget ( )
initLanguage() protected method

Initialize the plugin language.

protected void initLanguage ( $property 'language', $full false )
$property string

The name of language property in $pluginOptions.

$full boolean

Whether to use the full language string. Defaults to false which is the 2 (or 3) digit ISO-639 format. Defaults to 'language'.

parseDateFormat() protected method

Parses and sets plugin date format based on attribute type using \yii\helpers\FormatConverter. Currently this method is used only within the \kartik\date\DatePicker and \kartik\datetime\DateTimePicker\ widgets.

protected void parseDateFormat ( $type )
$type string

The attribute type whether date, datetime, or time.

throws \yii\base\InvalidConfigException
setLanguage() protected method

Sets the language JS file if it exists.

protected void setLanguage ( $prefix, $assetPath null, $filePath null, $suffix '.js' )
$prefix string

The language filename prefix

$assetPath string

The path to the assets

$filePath string

The path to the JS file with the file name prefix

$suffix string

The file name suffix - defaults to '.js'