You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the AjaxSubmitButton widget that renders an ajax button which is very similar to ajaxSubmitButton from Yii1 for Yii 2.
10
+
This is the powerful AjaxSubmitButton widget that renders an ajax button which is very similar to ajaxSubmitButton from Yii1 for Yii 2, but has many useful functions.
11
11
12
-
Example of usage of the widget with form and other custom widget (in this case Select2 widget).
12
+
### Basic Example
13
+
14
+
Example of usage of the widget with a custom widget (in this case Select2 widget).
13
15
14
16
The view:
15
17
```php
@@ -33,7 +35,6 @@ use demogorgorn\ajax\AjaxSubmitButton;
33
35
'ajaxOptions' => [
34
36
'type'=>'POST',
35
37
'url'=>'country/getinfo',
36
-
/*'cache' => false,*/
37
38
'success' => new \yii\web\JsExpression('function(html){
38
39
$("#output").html(html);
39
40
}'),
@@ -63,7 +64,86 @@ public function actionGetinfo()
63
64
}
64
65
```
65
66
66
-
Installation
67
+
### Example of usage with ActiveForm and client validation
68
+
69
+
The view:
70
+
```php
71
+
$form = ActiveForm::begin([
72
+
'id' => 'add-form',
73
+
'options' => ['class' => 'form-inline'],
74
+
]);
75
+
76
+
...
77
+
78
+
AjaxSubmitButton::begin([
79
+
'label' => 'Add',
80
+
'useWithActiveForm' => 'add-form',
81
+
'ajaxOptions' => [
82
+
'type' => 'POST',
83
+
'success' => new \yii\web\JsExpression("function(data) {
> As you can see it's quite easy to use the widget with ActiveForm - enough to set the ActiveForm's id to the 'useWithActiveForm' variable. (In this case id is 'add-form', without '#' symbol!).
98
+
99
+
100
+
### Client validation
101
+
102
+
As I said before the widget can be used with ActiveForm and client validation enabled. If you wish to disable it, just set ActiveForm's 'enableClientValidation' to false.
103
+
104
+
```php
105
+
$form = ActiveForm::begin([
106
+
'id' => 'filters-form',
107
+
'enableClientValidation' => false
108
+
]);
109
+
```
110
+
111
+
### Preloader use
112
+
113
+
It's possible to use the widget with your own custom preloader.
114
+
115
+
```php
116
+
<?php AjaxSubmitButton::begin([
117
+
'label' => 'Check',
118
+
'ajaxOptions' => [
119
+
'type'=>'POST',
120
+
'url'=>'country/getinfo',
121
+
'beforeSend' => new \yii\web\JsExpression('function(html){
122
+
... show preloader...
123
+
}'),
124
+
'success' => new \yii\web\JsExpression('function(html){
0 commit comments