Yii 2 Label In Place

Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads
Thankful to Krajee!
to get more out of us.

NOTE: This extension depends on the kartik-v/yii2-krajee-base extension which in turn depends on the yiisoft/yii2-bootstrap extension. Check the composer.json for this extension's requirements and dependencies that may be updated by composer.

The yii2-label-inplace package is a form enhancement widget for Yii framework 2.0 allowing in-field label support. This widget is a wrapper for the labelinplace plugin which is styled for Bootstrap 3.

The preferred way to install this extension is through composer. Either run:

$ php composer.phar require kartik-v/yii2-label-inplace "*"

or add:

"kartik-v/yii2-label-inplace": "*"

to the require section of your composer.json file. Then run:

php composer.phar update

to get the updated package on your application install.

The Label In Place widget enables you to setup the following properties:

  • type: string the type of input to be rendered. Defaults to LabelInPlace::TYPE_TEXT. One of the following types are supported:

    • textInput or LabelInPlace::TYPE_TEXT

    • textArea or LabelInPlace::TYPE_TEXTAREA

    • input or LabelInPlace::TYPE_HTML5

  • label: string|boolean the label content to be displayed. If set to false will not be parsed. If used with a model, and this is not set or is set to true, then it will be autogenerated from the model attribute label.

  • encodeLabel: boolean whether the label should be HTML-encoded. Defaults to true.

  • labelOptions: array the HTML attributes for the label tag.

  • defaultIndicators: boolean whether to show the arrow indicators by default after the label. Defaults to true.

  • options: array the HTML attributes for the input. Defaults to ['class'=>'form-control'].

  • pluginOptions: array the plugin settings/options for the labelinplace jquery plugin. Refer the plugin options documentation for details on the available configurable options.

Basic usage without active form or model.


Hide indicators and make a plain label


Style your own labels.


Change label positions, label indicators, and other plugin options.


Enter email address

Advanced usage with ActiveForm and model. Use three input types (html5, text, and textarea). Automatically convert model attribute labels. Note: You must deactivate the label rendering in the default active field template.

use kartik\widgets\ActiveForm;
use kartik\label\LabelInPlace;

$form = ActiveForm::begin();

// Basic usage without active form or model.
echo LabelInPlace::widget(['name'=>'username', 'label'=>'Username']);

// Hide indicators and make a plain label
echo LabelInPlace::widget([
    'name' => 'customer', 
    'label'=>'Customer',
    'defaultIndicators'=>false
]);

// Style your own labels.
echo LabelInPlace::widget([
    'name'=>'phone', 
    'label'=>'<i class="glyphicon glyphicon-phone"></i> Phone number',
    'encodeLabel'=> false
]);

// Change label positions, label indicators, and other plugin options.
echo LabelInPlace::widget([
    'name'=>'Enter code', 
    'type'=>LabelInPlace::TYPE_TEXT,
    'label'=>'<i class="glyphicon glyphicon-lock"></i> Type your code',
    'encodeLabel'=>false,
    'pluginOptions'=>[
        'labelPosition'=>'down',
        'labelArrowDown'=>' <i class="glyphicon glyphicon-chevron-down"></i>',
        'labelArrowUp'=>' <i class="glyphicon glyphicon-chevron-up"></i>',
        'labelArrowRight'=>' <i class="glyphicon glyphicon-chevron-right"></i>',
    ]
]);

// Advanced usage with ActiveForm and model. Use three input types (html5, text, and textarea). 
// Automatically convert model attribute labels. 
// Note: You must deactivate the label rendering in the default active field template.

$config = ['template'=>"{input}\n{error}\n{hint}"]; // config to deactivate label for ActiveField

echo $form->field($model, 'email', $config)->widget(LabelInPlace::classname(),[
    'type' => LabelInPlace::TYPE_HTML5,
    'options' => ['type' => 'email', 'class'=>'form-control']
]);
echo $form->field($model, 'phone', $config)->widget(LabelInPlace::classname()); 
echo $form->field($model, 'notes', $config)->widget(LabelInPlace::classname(), [
    'type' => LabelInPlace::TYPE_TEXTAREA
]);

ActiveForm::end();

yii2-label-inplace is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.