jwaldock/yii2-ajaxform

Provides AJAX submission for yii2 ActiveForm

Installs: 156

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

dev-master 2016-06-29 20:41 UTC

This package is not auto-updated.

Last update: 2024-04-19 17:36:45 UTC


README

Provides AJAX save for yii2 ActiveForm

Installation

The preferred way to install this extension is through composer.

Add

"repositories":[
    {
        "type": "git",
        "url": "https://github.com/jwaldock/yii2-ajaxform"
        "url": "https://path.to/your/repo"
    }
]

to your composer.json file.

Either run

php composer.phar require jwaldock/yii2-ajaxform:dev-master

or add.

"jwaldock/yii2-ajaxform": "dev-master"
"repositories":[
    {
        "type": "git",
        "url": "https://path.to/your/repo"
    }
]

to your composer.json file.

Either run

php composer.phar require jwaldock/yii2-ajaxform:dev-master

or add.

"jwaldock/yii2-ajaxform": "dev-master"

to the require section of your composer.json file

Usage

Set up AJAX validation for your

yiiAjaxForm provides three events submitBegin, submitEnd and submitFailed. Event handlers for these events should have the following function signatures:

// '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,
    ],
]);
?>