sandritsch91 / yii2-widget-autosize
为 yii2 定制的自动调整大小的控件
1.0.0
2024-04-16 11:36 UTC
Requires
- php: >=8.0
- bower-asset/autosize: ^4.0.0 | ^5.0.0 | ^6.0.0
- yiisoft/yii2: ^2.0.20
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-16 12:47:22 UTC
README
安装
通过 composer 安装此扩展是首选方式。
运行
php composer.phar require --prefer-dist sandritsch91/yii2-widget-autosize
或者在 composer.json 的 require 部分添加
"sandritsch91/yii2-widget-autosize": "*"
使用
与模型一起使用
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"); }' ] ]);
与 ActiveForm 一起使用
use sandritsch91\yii2-widget-autosize\Autosize; echo $form->field($model, 'content')->widget(Autosize::class, [ 'clientEvents' => [ 'autosize:resized' => 'function() { console.log("resized"); }' ] ]);
不与模型一起使用
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"); }' ] ]);
控件选项
- clientEvents: 要附加到文本区域的客户端事件。默认为 []
- autosize:resized: 当文本区域被调整大小时触发
- autosize:update: 分发此事件以更新文本区域。插件不会触发任何事件
- autosize:destroy: 分发此事件以销毁文本区域。插件不会触发任何事件
- htmlClass: 生成表单字段的类。默认为 yii\helpers\Html::class