sandritsch91 / yii2-widget-jsignature
为 Yii2 定制的 jSignature 小部件
1.1.0
2024-07-22 09:45 UTC
Requires
- php: >=8.0
- bower-asset/jsignature: ^2.0.0
- yiisoft/yii2: ^2.0.50
- yiisoft/yii2-imagine: ^2.2.0
This package is auto-updated.
Last update: 2024-09-22 12:04:53 UTC
README
一个 jSignature 小部件,用于 yii2
安装
安装此扩展的首选方法是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist sandritsch91/yii2-widget-jsignature
或者
"sandritsch91/yii2-widget-jsignature": "*"
将以下内容添加到您的 composer.json 文件的 require 部分中
注意事项
仅支持以下格式的签名加载
- native
- base30
如果您需要再次加载签名,请使用以下格式之一。
使用方法
小部件
与模型一起使用
use sandritsch91\yii2\jSignature\JSignature; echo JSignature::widget([ 'model' => $model, // The model to be used in the form 'attribute' => 'signature', // The attribute to be used in the form 'format' => 'svgbase64', // The format of the signature. Defaults to svgbase64 'htmlClass' => yii\helpers\Html::class, // Optional. The class used to generate the form field 'clientEvents' => [ // Optional. Pass the client events to be attached to the textarea 'change' => 'function() { console.log("changed"); }' ], 'wrapperOptions' => [...] // Optional. The options for the wrapper div ]);
与 ActiveForm 一起使用
use sandritsch91\yii2\jSignature\JSignature; echo $form->field($model, 'content')->widget(JSignature::class, [ 'format' => 'svgbase64', // The format of the signature. Defaults to svgbase64 'htmlClass' => yii\helpers\Html::class, // Optional. The class used to generate the form field 'clientEvents' => [ // Optional. Pass the client events to be attached to the textarea 'change' => 'function() { console.log("changed"); }' ], 'wrapperOptions' => [...] // Optional. The options for the wrapper div ]);
不与模型一起使用
use sandritsch91\yii2\jSignature\JSignature; echo JSignature::widget([ 'name' => 'myText', // The name of the input 'value' => ..., // The value of the input, depends on the format 'format' => 'svgbase64', // The format of the signature. Defaults to svgbase64 'htmlClass' => yii\helpers\Html::class, // Optional. The class used to generate the form field 'clientEvents' => [ // Optional. Pass the client events to be attached to the textarea 'change' => 'function() { console.log("changed"); }' ], 'wrapperOptions' => [...] // Optional. The options for the wrapper div ]);
小部件选项
- format: 签名格式。默认为 svgbase64
- default
- native
- base30
- svg
- svgbase64
- image
- htmlClass: 生成表单字段的类。默认为 yii\helpers\Html::class
- clientEvents: 将附加到 textarea 的客户端事件。默认为 []
- change: 在每笔后触发
- wrapperOptions: 包装 div 的选项。默认为 []
助手
使用 sandritsch91\yii2\jSignature\JSignatureHelper
将签名转换为不同的格式。
可能的转换包括
- base30 到 native
- native 到 svg
- base30 到 svg
- native 到 image
- base30 到 image