Commit 232bcd1d by Qiang Xue

Fixes #5171: Fixed the bug that ActiveForm + Pjax submit event is only triggered once.

parent 2d72bfba
...@@ -4,6 +4,7 @@ Yii Framework 2 Change Log ...@@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.0 under development 2.0.0 under development
----------------------- -----------------------
- Bug #5171: Fixed the bug that ActiveForm + Pjax submit event is only triggered once (qiangxue)
- Bug #5252: Null values are not properly handled by `RangeValidator` (githubjeka, qiangxue) - Bug #5252: Null values are not properly handled by `RangeValidator` (githubjeka, qiangxue)
- Bug #5260: `yii\i18n\Formatter::decimalSeparator` and `yii\i18n\Formatter::thousandSeparator` where not configurable when intl is not installed (execut, cebe) - Bug #5260: `yii\i18n\Formatter::decimalSeparator` and `yii\i18n\Formatter::thousandSeparator` where not configurable when intl is not installed (execut, cebe)
- Bug #5314: Fixed typo in the implementation of `yii\web\Session::getHasSessionId()` (qiangxue) - Bug #5314: Fixed typo in the implementation of `yii\web\Session::getHasSessionId()` (qiangxue)
...@@ -11,7 +12,7 @@ Yii Framework 2 Change Log ...@@ -11,7 +12,7 @@ Yii Framework 2 Change Log
- Bug #5336: `yii\bootstrap\DropDown` should register bootstrap plugin asset (zelenin) - Bug #5336: `yii\bootstrap\DropDown` should register bootstrap plugin asset (zelenin)
- Bug #5379: `Module::afterAction()` was called even when `beforeAction()` returned false (cebe) - Bug #5379: `Module::afterAction()` was called even when `beforeAction()` returned false (cebe)
- Bug #5423: `yii\behaviors\Cors` causes "undefined index" error when its `cors` is configured (qiangxue) - Bug #5423: `yii\behaviors\Cors` causes "undefined index" error when its `cors` is configured (qiangxue)
- Bug #5424: `Html::addCssStyle()` wasn't correctly setting style passed in array (kartik-v, samdark) - Bug #5424: `Html::addCssStyle()` wasn't correctly setting style passed in array (kartik-v, samdark)
- Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe) - Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe)
- Enh #4040: Added `$viewFile` and `$params` to the `EVENT_BEFORE_RENDER` and `EVENT_AFTER_RENDER` events for `View` (qiangxue) - Enh #4040: Added `$viewFile` and `$params` to the `EVENT_BEFORE_RENDER` and `EVENT_AFTER_RENDER` events for `View` (qiangxue)
- Enh #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations (samdark) - Enh #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations (samdark)
......
...@@ -256,9 +256,10 @@ ...@@ -256,9 +256,10 @@
data = $form.data('yiiActiveForm'), data = $form.data('yiiActiveForm'),
needAjaxValidation = false, needAjaxValidation = false,
messages = {}, messages = {},
deferreds = deferredArray(); deferreds = deferredArray(),
submitting = data.submitting;
if (data.submitting) { if (submitting) {
var event = $.Event(events.beforeValidate); var event = $.Event(events.beforeValidate);
$form.trigger(event, [messages, deferreds]); $form.trigger(event, [messages, deferreds]);
if (event.result === false) { if (event.result === false) {
...@@ -324,9 +325,9 @@ ...@@ -324,9 +325,9 @@
delete msgs[this.id]; delete msgs[this.id];
} }
}); });
updateInputs($form, $.extend(messages, msgs)); updateInputs($form, $.extend(messages, msgs), submitting);
} else { } else {
updateInputs($form, messages); updateInputs($form, messages, submitting);
} }
}, },
error: function () { error: function () {
...@@ -336,10 +337,10 @@ ...@@ -336,10 +337,10 @@
} else if (data.submitting) { } else if (data.submitting) {
// delay callback so that the form can be submitted without problem // delay callback so that the form can be submitted without problem
setTimeout(function () { setTimeout(function () {
updateInputs($form, messages); updateInputs($form, messages, submitting);
}, 200); }, 200);
} else { } else {
updateInputs($form, messages); updateInputs($form, messages, submitting);
} }
}); });
}, },
...@@ -349,10 +350,6 @@ ...@@ -349,10 +350,6 @@
data = $form.data('yiiActiveForm'); data = $form.data('yiiActiveForm');
if (data.validated) { if (data.validated) {
if (!data.submitting) {
// form is being submitted. Do nothing to avoid duplicated form submission
return false;
}
data.submitting = false; data.submitting = false;
var event = $.Event(events.beforeSubmit); var event = $.Event(events.beforeSubmit);
$form.trigger(event); $form.trigger(event);
...@@ -472,11 +469,12 @@ ...@@ -472,11 +469,12 @@
* Updates the error messages and the input containers for all applicable attributes * Updates the error messages and the input containers for all applicable attributes
* @param $form the form jQuery object * @param $form the form jQuery object
* @param messages array the validation error messages * @param messages array the validation error messages
* @param submitting whether this method is called after validation triggered by form submission
*/ */
var updateInputs = function ($form, messages) { var updateInputs = function ($form, messages, submitting) {
var data = $form.data('yiiActiveForm'); var data = $form.data('yiiActiveForm');
if (data.submitting) { if (submitting) {
var errorInputs = []; var errorInputs = [];
$.each(data.attributes, function () { $.each(data.attributes, function () {
if (!this.cancelled && updateInput($form, this, messages)) { if (!this.cancelled && updateInput($form, this, messages)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment