sandritsch91/yii2-widget-autosize

An autosize widget for yii2

1.0.0 2024-04-16 11:36 UTC

This package is auto-updated.

Last update: 2024-11-16 13:20:52 UTC


README

An autosize widget for yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist sandritsch91/yii2-widget-autosize

or add

"sandritsch91/yii2-widget-autosize": "*"

to the require section of your composer.json

Usage

with a model:

use sandritsch91\yii2-widget-autosize\Autosize;

echo Autosize::widget([
    'model' => $model,                          // The model to be used in the form
    'attribute' => 'content',                   // The attribute to be used in the form
    'htmlClass' => yii\bootstrap5\Html::class,  // Optional. The class used to generate the form field
    'clientEvents' => [                         // Optional. Pass the client events to be attached to the textarea
        'autosize:resized' => 'function() { console.log("resized"); }'
    ]
]);

with an ActiveForm:

use sandritsch91\yii2-widget-autosize\Autosize;

echo $form->field($model, 'content')->widget(Autosize::class, [
    'clientEvents' => [
        'autosize:resized' => 'function() { console.log("resized"); }'
    ]
]);

without a model:

use sandritsch91\yii2-widget-autosize\Autosize;

echo Autosize::widget([
    'name' => 'myText',         // The name of the input
    'value' => 'Hello World',   // The value of the input
    'clientEvents' => [
        'autosize:resized' => 'function() { console.log("resized"); }'
    ]
]);

Widget options

  • clientEvents: The client events to be attached to the textarea. Defaults to []
    • autosize:resized: Triggered when the textarea is resized
    • autosize:update: Dispatch this event to update the textarea. No event is triggered by the plugin
    • autosize:destroy: Dispatch this event to destroy the textarea. No event is triggered by the plugin
  • htmlClass: The class used to generate the form field. Defaults to yii\helpers\Html::class