The yii2-widgets package is a collection of useful widgets for Yii Framework 2 extending functionalities for Bootstrap 5.x / 4.x / 3.x, with added jQuery plugins, CSS3, and HTML 5 features. The widgets have been specifically optimized for Yii 2 and categorized as input widgets, progress widgets, navigation widgets, and notification widgets.
This extension has now matured to contain the most needed basic widgets for Yii 2 input and navigation controls. In order to support this extension better, any
additional input and navigation widgets will be created separately. Listed below are the additional widgets that are related to similar functionality like the
yii2-widgets
, but have been created as separate extensions (these widgets depend on kartik-v/yii2-widgets
).
yii2-dropdown-x: Extended Bootstrap 5.x / 4.x / 3.x dropdown menu for Yii 2.0
yii2-nav-x: Extended Bootstrap 5.x / 4.x / 3.x navigation menu for Yii 2.0
yii2-context-menu: Bootstrap 5.x / 4.x / 3.x context menu for Yii 2.0
yii2-slider: Bootstrap 5.x / 4.x / 3.x Slider control for Yii 2.0
yii2-sortable: Create sortable lists and grids using simple drag and drop.
yii2-sortable-input: Input widget for yii2-sortable allowing you to store the sort order.
yii2-money: Masked money input widget for Yii 2.0.
yii2-checkbox-x: Bootstrap 5.x / 4.x / 3.x extended checkbox widget with 3 states and more styles for Yii 2.0.
yii2-date-range: An extended Bootstrap library date range picker widget for Yii 2.0.
yii2-label-inplace: A form enhancement widget for Yii framework 2.0 allowing in-field label support.
Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)
The yii2-widgets
extension can be installed automatically or manually using one of these options:
Installation via Composer is the recommended and most easy option to install Krajee Yii2 extensions. You can install yii2-widgets
via composer
package manager. Either run:
$ php composer.phar require kartik-v/yii2-widgets "dev-master"
or add:
"kartik-v/yii2-widgets": "dev-master"
to your application's composer.json
file.
You may also manually install the extension to your project (in case your composer install does not work). Just download the source ZIP or TAR ball and extract the extension asset files and folders into your project. You may need to install dependencies manually and also set the namespaces to the extensions in your Yii2 extensions configurations manually.
\kartik\base\InputWidget class
, which in turn extends the \yii\widgets\InputWidget
class.
kartik\form\ActiveField
. For example, you can set the new autoPlaceholder
property within fieldConfig
which will hide the label and display it as a placeholder.
View details and demos.
use kartik\form\ActiveForm; $form = kartik\form\ActiveForm::begin( [ 'id' => 'signup-form', 'enableAjaxValidation' => true, 'fieldConfig' => [ 'autoPlaceholder'=>true ] ]);
ActiveField
class is automatically initialized within the kartik\form\ActiveForm
class.
So, one does not need to explicitly call this class, when calling kartik\form\ActiveForm
.
View details and demos. Also, view a complete demo on HTML5 inputs.
use kartik\form\ActiveForm; $form = ActiveForm::begin(); echo $form->field($model, 'username'); ActiveForm::end();
View details and demo.
use kartik\depdrop\DepDrop // Normal parent select echo $form->field($model, 'cat')->dropDownList($catList, ['id'=>'cat-id']); // Dependent Dropdown echo $form->field($model, 'subcat')->widget(DepDrop::classname(), [ 'options' => ['id'=>'subcat-id'], 'pluginOptions'=>[ 'depends'=>['cat-id'], 'placeholder' => 'Select...', 'url' => Url::to(['/site/subcat']) ] ]);
The Select2 widget is a Yii 2 wrapper for the Select2 jQuery plugin. This input widget is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results. The widget is specially styled for Bootstrap library. The widget allows graceful degradation to a normal HTML select or text input, if the browser does not support JQuery. You can setup model validation rules for a model attribute that uses Select2 widget for input like any other field.
New release v2.0: The widget has been revamped and upgraded to v2.0 to implement Select2 plugin release v4.0. Select2 release v4.0 is a major rewrite over Select2 v4.x / 3.x and hence quite a few enhancements or changes should be expected. The following new functionalities and changes should be expected with this release.
New theme
property that allows you to set themes in Select2 to style your widget.
A brand new theme by Krajee Select2::THEME_KRAJEE
is now available and specially styled for yii2-widget-select2. This will help achieve various widget specific enhancements and features.
This theme matches the Bootstrap library styling with various enhancements.
Additional themes provided in form of Select2::THEME_DEFAULT
, Select2::THEME_CLASSIC
, and Select2::THEME_BOOTSTRAP
. One can
add their own custom theme and configure the widget
No more query
plugin property needed. It is also not mandatory to configure data
even if you have not set tags
or query
or ajax
. Widget will intelligently evaluate the properties and default list values.
Enhanced tagging support. Use it just like a multiple select but with taggable values. In addition, one can create tags on the fly.
Enhanced ajax support. Refer the usage demos for details.
The initSelection
method of Select2 3.5.x plugin is obsolete/removed. New initValueText
property is been provided with the Select2 widget to cater to this (e.g. for ajax based loading).
Ability to disable selective option values in the Select2 dropdown OR add HTML attributes to selective options.
Enhancement by Krajee to disable the search box to use like a normal select.
Enhancements to locales and translations. Allow multiple language Select2 widgets on the same page.
View details and demo.
use kartik\select2\Select2 // usage with ActiveForm and model echo \$form->field(\$model, 'state_1')->widget(Select2::classname(), [ 'language' => 'de', 'data' => $data, 'options' => ['placeholder' => 'Select a state ...'], 'pluginOptions' => [ 'allowClear' => true ], ]);
typeahead.js
, which is described as
a fast and fully-featured autocomplete library. The widget is specially styled for Bootstrap library.
The widget allows graceful degradation to a normal HTML text input, if the browser does not support JQuery.
You can setup model validation rules for a model attribute that uses TypeaheadBasic widget for input like any other field.
View details and demo.
use kartik\widgets\TypeaheadBasic // usage with ActiveForm and model echo $form->field($model, 'state_3')->widget(TypeaheadBasic::classname(), [ 'options' => ['placeholder' => 'Filter as you type ...'], 'dataset' => [ [ 'local' => $data, 'limit' => 10 ] ] ]);
typeahead.js
, which is described as
a fast and fully-featured autocomplete library. The widget is specially styled for Bootstrap library.
The widget allows graceful degradation to a normal HTML text input, if the browser does not support JQuery.
You can setup model validation rules for a model attribute that uses Typeahead widget for input like any other field.
View details and demo.
use kartik\widgets\Typeahead // usage with ActiveForm and model echo $form->field($model, 'state_3')->widget(Typeahead::classname(), [ 'options' => ['placeholder' => 'Filter as you type ...'], 'dataset' => [ [ 'local' => $data, 'limit' => 10 ] ] ]);
View details and demo.
use kartik\widgets\DatePicker // usage without model echo '<label>Check Issue Date</label>'; echo DatePicker::widget([ 'name' => 'check_issue_date', 'value' => date('d-M-Y', strtotime('+2 days')),, 'options' => ['placeholder' => 'Select issue date ...'], 'pluginOptions' => [ 'format' => 'dd-M-yyyy', 'todayHighlight' => true ] ]);
View details and demo.
use kartik\widgets\TimePicker // usage without model echo '<label>Event Time</label>'; echo TimePicker::widget([ 'name' => 'event-time', 'pluginOptions' => [ 'minuteStep' => 1, 'showSeconds' => true, 'showMeridian' => false ] ]);
View details and demo.
use kartik\widgets\DateTimePicker // usage without model echo '<label>Operation Time</label>'; echo DatePicker::widget([ 'name' => 'operation_time', 'value' => date('d-M-Y g:i A', strtotime('+2 days')),, 'options' => ['placeholder' => 'Select operating time ...'], 'convertFormat' => true, 'pluginOptions' => [ 'format' => 'd-M-Y g:i A', 'todayHighlight' => true ] ]);
View details and demo.
use kartik ouchspin\TouchSpin echo TouchSpin::widget([ 'name' => 'volume', 'options' => ['placeholder' => 'Adjust...'], 'pluginOptions' => ['step' => 1] ]);
use kartik\widgets\FileInput echo FileInput::widget([ 'name' => 'attachments', 'options' => ['multiple' => true], 'pluginOptions' => ['previewFileType' => 'any'] ]);
useNative
option to true
. Else, the Spectrum plugin polyfills for unsupported browser versions. The widget enhances the plugin and color input with various features including the following:
HTML5 color input
for unsupported browser versions.use kartik\color\ColorInput echo ColorInput::widget([ 'name' => 'color', 'options' => ['placeholder' => 'Select color...'] ]);
use kartik ange\RangeInput echo RangeInput::widget([ 'name' => 'brightness', 'html5Options' => ['min' => 0, 'max' => 1, 'step' => 1], 'options' => ['placeholder' => 'Control brightness...'], 'addon' => ['append' => ['content' => '%']], ]);
use kartik\widgets\SwitchInput echo SwitchInput::widget([ 'name' => 'activation_status', 'pluginOptions' => ['size' => 'large'] ]);
use kartik\widgets\StarRating echo StarRating::widget([ 'name' => 'rating', 'pluginOptions' => ['size' => 'lg'] ]);
View details and demo
use kartik\widgets\Spinner; echo Spinner::widget(['preset' => 'large', 'align' => 'left']);
View details and demo
use kartik\sidenav\SideNav; echo SideNav::widget(['type' => SideNav::TYPE_SUCCESS, 'items' => [ ['label' => 'Home', 'icon' => 'home', 'url' => Url::to(['/site/home', 'type'=>$type]), 'active' => ($item == 'home')], ['label' => 'Books', 'icon' => 'book', 'items' => [ ['label' => '<span class="pull-right float-right float-end badge">10</span> New Arrivals', 'url' => Url::to(['/site/new-arrivals', 'type'=>$type]), 'active' => ($item == 'new-arrivals')], ['label' => '<span class="pull-right float-right float-end badge">5</span> Most Popular', 'url' => Url::to(['/site/most-popular', 'type'=>$type]), 'active' => ($item == 'most-popular')], ['label' => 'Read Online', 'icon' => 'cloud', 'items' => [ ['label' => 'Online 1', 'url' => Url::to(['/site/online-1', 'type'=>$type]), 'active' => ($item == 'online-1')], ['label' => 'Online 2', 'url' => Url::to(['/site/online-2', 'type'=>$type]), 'active' => ($item == 'online-2')] ]], ]], ]);
\yii\bootstrap\Alert
class with additional features and enhancements:
Alert Types: Easily set an alert style through the type
property. Adds two new types other than the 4 standard bootstrap alert types.
Icon & Title Section: Ability to set a stylish title separator section and add an icon and title for each alert as a header.
Fade: Ability to set a fade duration to automatically fade out the alerts after display.
View details and demo.
use kartik\widgets\Alert; echo Alert::widget([ 'type' => Alert::TYPE_INFO, 'title' => 'Note', 'titleOptions' => ['icon' => 'info-sign'], 'body' => 'This is an informative alert' ]);
Alert Positioning: Position and align growl notifications at any corner of your page.
Icon & Title Section: Ability to set a stylish title separator section and add an icon and title for each alert as a header.
Fade: Ability to set a fade duration to automatically fade out the alerts after display.
Plugin Configuration: Ability to configure various options by passing parameters to the JQuery plugin.
View details and demo.
use kartik\widgets\Growl; echo Growl::widget([ 'type' => Growl::TYPE_SUCCESS, 'icon' => 'fas fa-check-circle', 'title' => 'Note', 'showSeparator' => true, 'body' => 'This is a successful growling alert.' ]);
\kartik\widget\Alert
or kartik\widget\Growl
widgets in a single block. The widget by default stacks the alert messages vertically on the current page.
The widget offers the following features:
Session Flashes: The widget automatically reads the messages stored in session flash via Yii::$app->session->setFlash()
. All the flash messages stored for the session are displayed and removed from the session.
Custom Stacked Alerts: You can override the useSessionFlash
setting to false
and display your own alert messages in a single block.
Alert Widget Types: You can choose the TYPE_ALERT
style or the TYPE_GROWL
to choose the widget for triggering your alert notifications.
View details and demo.
use kartik\widgets\AlertBlock; echo AlertBlock::widget([ 'type' => AlertBlock::TYPE_ALERT, 'useSessionFlash' => true ]);
Comments & Discussion
Note
You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.
The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.