tonisormisson / yii2-json-form
此包的最新版本(1.5.3)没有可用的许可信息。
yii2的JSON表单视图小部件
1.5.3
2024-04-03 11:20 UTC
Requires
- php: >=8.0.2
- kartik-v/yii2-password: ^1.5.3
- kartik-v/yii2-widget-datepicker: ^1.4.0
- kartik-v/yii2-widget-datetimepicker: ^1.4.0
- kartik-v/yii2-widget-select2: ^2.1.0
- yiisoft/yii2: ^2.0.5
Requires (Dev)
- phpstan/phpstan: ^1.8
README
示例用法
<?php
use tonisormisson\jsonform\JsonForm;
$jsonData = '{"username":"admin","password":"password"}';
$variables = [
'username'=>[
'label' => Yii::t('app','Username'),
],
'password'=>[
'label' => Yii::t('app','Password'),
'type' => JsonForm::TYPE_PASSWORD,
],
];
echo JsonForm::widget([
'id' => 'my-id',
'json' => $jsonData,
'jsonFieldId' => 'my-credentials-input-field',
'variables' => $variables,
'labels' => false,
]);
// the filed where the changed json will be stored
// hide this !!
echo Html::textarea('my-credentials-input-field','', ['id' => 'my-credentials-input-field']);
上述示例的输出
非键版本
<?php
use tonisormisson\jsonform\JsonForm;
$jsonData = '["foo", "bar", "bazinga"]';
echo JsonForm::widget([
'id' => 'my-id',
'json' => $jsonData,
'jsonFieldId' => 'my-credentials-input-field',
'isKeyed' => false,
]);
// the filed where the changed json will be stored
// hide this !!
echo Html::textarea('my-credentials-input-field','', ['id' => 'my-credentials-input-field']);
示例用法 Select2
// ######################### example 3 select
$jsonData = '{"select2":3}';
$variables = [
'select2'=>[
'label' => Yii::t('app','A select 2 example'),
'type' => JsonForm::TYPE_SELECT2,
'select' => [
1 => "one",
2 => "two",
3 => "three"
],
'options' => ['placeholder' => 'Select a number ...'],
'pluginOptions' => [
'allowClear' => true
]
],
];
echo JsonForm::widget([
'id' => 'my-id-3',
'json' => $jsonData,
'jsonFieldId' => 'my-credentials-input-field-3',
'variables' => $variables,
]);
echo Html::textarea('my-credentials-input-field-3','', ['id' => 'my-credentials-input-field-3']);