jwaldock / yii2-ajaxform
为 yii2 ActiveForm 提供AJAX提交功能
dev-master
2016-06-29 20:41 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-20 19:40:17 UTC
README
为 yii2 ActiveForm 提供AJAX保存功能
安装
安装此扩展的首选方式是通过 composer。
添加
"repositories":[
{
"type": "git",
"url": "https://github.com/jwaldock/yii2-ajaxform"
"url": "https://path.to/your/repo"
}
]
到您的 composer.json
文件中。
运行以下命令之一
php composer.phar require jwaldock/yii2-ajaxform:dev-master
或者添加。
"jwaldock/yii2-ajaxform": "dev-master"
"repositories":[
{
"type": "git",
"url": "https://path.to/your/repo"
}
]
到您的 composer.json
文件中。
运行以下命令之一
php composer.phar require jwaldock/yii2-ajaxform:dev-master
或者添加。
"jwaldock/yii2-ajaxform": "dev-master"
到您的 composer.json
文件的 require 部分
使用方法
设置您的
yiiAjaxForm
提供了三个事件 submitBegin
、submitEnd
和 submitFailed
。这些事件的处理器应具有以下函数签名
// 'submitBegin' event function (event) { // handle submission begin }
// 'submitEnd' event function (event, success, modeldata) { if (success) { // handle successful save return } // handle failed save }
// submitFailed function (event, xhr) { // handle failure }
public function actions() { return [ 'submit-model' => [ 'class' => 'jwaldock\ajaxform\AjaxSubmitAction', 'modelClass' => 'model', // the fully qualified class name of the model 'tabular' => true, // set to true if using a tabular form - defaults to false 'scenario' => 'model-scenario' // optional model scenario ], // other actions ]; }
<?php $js = <<<JS function (event, success, modeldata) { if (success) { // handle successful save } } JS; AjaxFormWidget::widget([ 'form' => $form, // ActiveForm 'disableSubmit' => true, // whether to disable the submit button on submitting the form 'savingContent' => 'Saving...', the inner html content of the submit button when saving 'clientEvents' => [ 'submitEnd' => $js, ], ]); ?>