Commit de63a46d by Qiang Xue

Fixes #4984.

parent b604bc56
...@@ -256,8 +256,7 @@ new ones save the following code as `convert.php` that should be placed in the s ...@@ -256,8 +256,7 @@ new ones save the following code as `convert.php` that should be placed in the s
} elseif (attribute.id === 'something') { } elseif (attribute.id === 'something') {
// the event is triggered before validating "something" // the event is triggered before validating "something"
} }
// if you want to cancel the validation, do the following: // if you want to cancel the validation, return a boolean false.
// event.isValid = false;
}); });
``` ```
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* The signature of the event handler should be: * The signature of the event handler should be:
* function (event, messages, deferreds, attribute) * function (event, messages, deferreds, attribute)
* where * where
* - event: an Event object. You can set event.isValid to be false to stop validating the form or attribute * - event: an Event object.
* - messages: error messages. When attribute is undefined, this parameter is an associative array * - messages: error messages. When attribute is undefined, this parameter is an associative array
* with keys being attribute IDs and values being error messages for the corresponding attributes. * with keys being attribute IDs and values being error messages for the corresponding attributes.
* When attribute is given, this parameter is an array of the error messages for that attribute. * When attribute is given, this parameter is an array of the error messages for that attribute.
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
* - attribute: an attribute object. Please refer to attributeDefaults for the structure. * - attribute: an attribute object. Please refer to attributeDefaults for the structure.
* If this is undefined, it means the event is triggered before validating the whole form. * If this is undefined, it means the event is triggered before validating the whole form.
* Otherwise it means the event is triggered before validating the specified attribute. * Otherwise it means the event is triggered before validating the specified attribute.
*
* If the handler returns a boolean false, it will stop further validation after this event.
*/ */
beforeValidate: 'beforeValidate', beforeValidate: 'beforeValidate',
/** /**
...@@ -58,6 +60,8 @@ ...@@ -58,6 +60,8 @@
* The signature of the event handler should be: * The signature of the event handler should be:
* function (event) * function (event)
* where event is an Event object. * where event is an Event object.
*
* If the handler returns a boolean false, it will stop further validation after this event.
*/ */
beforeSubmit: 'beforeSubmit', beforeSubmit: 'beforeSubmit',
/** /**
...@@ -237,9 +241,9 @@ ...@@ -237,9 +241,9 @@
deferreds = deferredArray(); deferreds = deferredArray();
if (data.submitting) { if (data.submitting) {
var event = $.Event(events.beforeValidate, {'isValid': true}); var event = $.Event(events.beforeValidate);
$form.trigger(event, [messages, deferreds]); $form.trigger(event, [messages, deferreds]);
if (!event.isValid) { if (event.result === false) {
data.submitting = false; data.submitting = false;
return; return;
} }
...@@ -254,9 +258,9 @@ ...@@ -254,9 +258,9 @@
msg = []; msg = [];
messages[this.id] = msg; messages[this.id] = msg;
} }
var event = $.Event(events.beforeValidate, {'isValid': true}); var event = $.Event(events.beforeValidate);
$form.trigger(event, [msg, deferreds, this]); $form.trigger(event, [msg, deferreds, this]);
if (event.isValid) { if (event.result !== false) {
if (this.validate) { if (this.validate) {
this.validate(this, getValue($form, this), msg, deferreds); this.validate(this, getValue($form, this), msg, deferreds);
} }
...@@ -327,9 +331,9 @@ ...@@ -327,9 +331,9 @@
data = $form.data('yiiActiveForm'); data = $form.data('yiiActiveForm');
if (data.validated) { if (data.validated) {
var event = $.Event(events.beforeSubmit, {'isValid': true}); var event = $.Event(events.beforeSubmit);
$form.trigger(event, [$form]); $form.trigger(event, [$form]);
if (!event.isValid) { if (event.result === false) {
data.validated = false; data.validated = false;
data.submitting = false; data.submitting = false;
return false; return false;
......
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