plesk / yii2-standalone-search-form
Plesk 扩展程序,用于在 Yii2 框架中创建独立搜索表单。
2.2.0
2020-04-29 11:31 UTC
Requires
- php: >=5.4
- plesk/yii2-pjax: ^1.0.0
- yiisoft/yii2: ^2.0.5
- yiisoft/yii2-bootstrap4: ^2.0.0
README
此扩展程序提供了一种创建将通过 PJAX 提交和验证的表单的能力。提交表单后,将使用 PJAX 更新在表单设置中设置的页面片段。这种方法可以在不实现 Yii2 表单 AJAX 验证和 Yii2 客户端验证的情况下创建 AJAX 表单。该表单是自适应的。
此扩展程序使用 yiisoft/yii2-bootstrap4 扩展。
安装
安装此扩展的首选方法是通过 composer
composer require "plesk/yii2-standalone-search-form:^2.0.0"
配置
[ 'components' => [ 'pjax' => [ 'class' => 'plesk\yii2pjax\Component', ], ], ]
API
示例
use plesk\standalonesearchform\SearchForm; echo SearchForm::widget([ 'model' => $searchModel, 'fields' => [ [ 'type' => 'widget', 'attribute' => 'project_id', 'width' => 'full-wide', 'options' => [ Chosen::className(), [ 'items' => ArrayHelper::map($projects, 'id', 'name'), ] ] ], [ 'type' => 'checkbox', 'attribute' => 'showCasesCount', 'width' => 'full-wide', 'options' => [[], false] ], ], 'resultAreaPjaxOptions' => ['id' => 'result-area-pjax-grid', 'timeout' => 1000], ]);
use plesk\standalonesearchform\SearchForm; echo SearchForm::widget([ 'model' => $searchModel, 'collapse' => true, 'fields' => [ [ 'type' => 'widget', 'attribute' => 'project_id', 'width' => 'full-wide', 'options' => [ Chosen::className(), [ 'items' => ArrayHelper::map($projects, 'id', 'name'), ] ] ], [ 'type' => 'widget', 'attribute' => 'dateCreated', 'width' => 'long', 'range' => true, 'options' => [ DateTimePicker::className(), ] ], ], 'resultAreaPjaxOptions' => ['id' => 'plesk-pjax-search-result', 'timeout' => 30000], 'buttons' => [ [ 'type' => 'submitButton', 'options' => [ 'Search it!', ['class' => 'btn btn-primary'], ] ], [ 'type' => 'widget', 'options' => [ \app\components\widgets\clearButton\Widget::class, [ 'content' => 'Clear it!', 'buttonOptions' => ['class' => 'btn btn-danger'], ], ] ] ], ]);
有关详细信息,请参阅 SearchForm 类
为了处理 pjax 错误,您应该在调用此小部件之前设置您的处理器。
<head> <?php $this->registerJs( '$(document).on(\'pjax:error\', function(event, xhr, textStatus, error, options) { pleskMessageBox.options.title = error; pleskMessageBox.alert(xhr.responseText); });' ); ?> </head>
异常
- plesk\standalonesearchform\exceptions\Exception
All exceptions thrown by the extension, extend this exception.