eluhr/yii2-jedi-editor
最新稳定版本:1.1.0
Composer 安装命令:
composer require eluhr/yii2-jedi-editor
包简介
Yii2 asset bundle and input widget for germanbisurgi/jedison
README 文档
README
Yii2 AssetBundle and Input Widget for germanbisurgi/jedison
Installation
The preferred way to install this extension is through composer.
Either run
composer require eluhr/yii2-jedison-editor
or add
"eluhr/yii2-jedison-editor": "*"
to the require section of your composer.json file.
Usage
<?php /** * @var \yii\base\Model $model * @var yii\web\View $this */ use eluhr\jedison\widgets\JedisonEditor; use yii\web\JsExpression; // Schema can either be of type string, array or stdClass. $schema1 = '{}'; $schema2 = []; // Without a model echo JedisonEditor::widget([ 'id' => 'my-jedi', 'name' => 'editor', 'schema' => $schema1, // Update theme, see: https://github.com/germanbisurgi/jedison/tree/main?tab=readme-ov-file#theme 'theme' => JedisonEditor::THEME_THEME_BOOTSTRAP3, 'pluginOptions' => [ // No ref parser 'refParser' => null ], 'pluginEvents' => [ 'change' => new JsExpression('() => console.log(window["my-jedi"].getValue())'), ] ]); // Alternative example on how to listen to change event $this->registerJs(<<<JS window['my-jedi'].on('change', () => { console.log(window['my-jedi'].getValue()) }) JS); // With a model echo JedisonEditor::widget([ 'model' => $model, 'attribute' => 'attribute_name', 'schema' => $schema2, 'pluginOptions' => [ // You can also set the theme like this 'theme' => new JsExpression('new Jedison.ThemeBootstrap3()'), 'showErrors' => 'always', // "change" or "never" is also possible ], 'disabled' => false ]);
Example model
<?php namespace app\models; use eluhr\jedison\validators\JsonSchemaValidator; use app\filters\MyCustomFilter; use yii\base\Model; class MyModel extends Model { public $title; public $value; public function rules() { $rules = parent::rules(); $rules[] = [ 'title', 'integer', 'enableClientValidation' => false, ]; $rules[] = [ 'value', JsonSchemaValidator::class, 'schema' => static::getJsonSchema(), 'filters' => static::getJsonSchemaFilters() ]; return $rules; } public function getJsonSchemaFilters(): array { return [ 'custom' => new MyCustomFilter() // Implement your custom filter if needed. See: https://opis.io/json-schema/2.x/php-filter.html Filter must inherit from Opis\JsonSchema\Filter ]; } public static function getJsonSchema(): string { return <<<JSON { "title": "Test", "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string", "\$filters": { "\$func": "custom" } } } } JSON; } } ?>
Options
$containerOptions(array): HTML attributes for the<textarea>container tag.$pluginOptions(array): Options to be passed to the Jedison validator. See: https://github.com/germanbisurgi/jedison?tab=readme-ov-file#instance-options$pluginEvents(array): Events to be passed to the Jedison validator.$showModelErrors(bool): Shows model errors.$mapTranslations(bool): Use Jedison-translated error messages when showing model errors, if available.$filterConstraints(array): Filter error messages by constraints to hide unnecessary messages.
For further information about the usage of the jedison editor please refer to the docs
统计信息
- 总下载量: 2.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-30