Skip to content

Commit 4756791

Browse files
authored
Update of Readme
1 parent e37725b commit 4756791

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

README.md

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AjaxSubmitButton for Yii 2
1+
# AjaxSubmitButton for Yii 2
22
=====================================
33

44
[![Latest Stable Version](https://poser.pugx.org/demogorgorn/yii2-ajax-submit-button/v/stable)](https://packagist.org/packages/demogorgorn/yii2-ajax-submit-button)
@@ -7,9 +7,11 @@ AjaxSubmitButton for Yii 2
77
[![Monthly Downloads](https://poser.pugx.org/demogorgorn/yii2-ajax-submit-button/d/monthly)](https://packagist.org/packages/demogorgorn/yii2-ajax-submit-button)
88

99

10-
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.
1111

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).
1315

1416
The view:
1517
```php
@@ -33,7 +35,6 @@ use demogorgorn\ajax\AjaxSubmitButton;
3335
'ajaxOptions' => [
3436
'type'=>'POST',
3537
'url'=>'country/getinfo',
36-
/*'cache' => false,*/
3738
'success' => new \yii\web\JsExpression('function(html){
3839
$("#output").html(html);
3940
}'),
@@ -63,7 +64,86 @@ public function actionGetinfo()
6364
}
6465
```
6566

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) {
84+
if (data.status == true)
85+
{
86+
closeTopbar();
87+
}
88+
}"),
89+
],
90+
'options' => ['class' => 'btn btn-primary', 'type' => 'submit', 'id' =>'add-button'],
91+
]);
92+
AjaxSubmitButton::end();
93+
94+
ActiveForm::end()
95+
```
96+
97+
> 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){
125+
... hide preloader ...
126+
}'),
127+
],
128+
'options' => ['class' => 'customclass', 'type' => 'submit'],
129+
]);
130+
AjaxSubmitButton::end();
131+
?>
132+
```
133+
134+
### Widget's options
135+
136+
Variable | Description
137+
------------ | -------------
138+
ajaxOptions | array of js ajax options.
139+
options | array of the HTML attributes and other options of the widget's container tag
140+
tagName | (string) the tag to use to render the button (by default is 'button'. You can specify, for example, 'a' tag).
141+
label | (string) button's label
142+
encodeLabel | (boolean) whether the label should be HTML-encoded.
143+
clickedButtonVarName | (string) js object name. It is unused when useWithActiveForm is enabled.
144+
useWithActiveForm | (boolean) whether the button should not be used with ActiveForm. (string) the id of ActiveForm to use the button with.
145+
146+
## Installation
67147
------------
68148

69149
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

0 commit comments

Comments
 (0)