Commit 9fc4c380 by Qiang Xue

form wip

parent aa8061b0
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
}, },
submitForm: function () { submitForm: function () {
var $form = $(this), var $form = this,
data = $form.data('yiiActiveForm'); data = $form.data('yiiActiveForm');
if (data.validated) { if (data.validated) {
// continue submitting the form since validation passes // continue submitting the form since validation passes
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
hasError = updateInput($form, this, messages) || hasError; hasError = updateInput($form, this, messages) || hasError;
}); });
updateSummary($form, messages); updateSummary($form, messages);
if (!data.settings.afterValidate || data.settings.afterValidate($form, data, hasError)) { if (!data.settings.afterValidate || data.settings.afterValidate($form, messages, hasError)) {
if (!hasError) { if (!hasError) {
data.validated = true; data.validated = true;
var $button = data.submitObject || $form.find(':submit:first'); var $button = data.submitObject || $form.find(':submit:first');
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
}, },
resetForm: function () { resetForm: function () {
var $form = $(this); var $form = this;
var data = $form.data('yiiActiveForm'); var data = $form.data('yiiActiveForm');
// Because we bind directly to a form reset event instead of a reset button (that may not exist), // Because we bind directly to a form reset event instead of a reset button (that may not exist),
// when this function is executed form input values have not been reset yet. // when this function is executed form input values have not been reset yet.
...@@ -190,26 +190,6 @@ ...@@ -190,26 +190,6 @@
} }
}; };
var getValue = function ($form, attribute) {
var $input = findInput($form, attribute);
var type = $input.attr('type');
if (type === 'checkbox' || type === 'radio') {
return $input.filter(':checked').val();
} else {
return $input.val();
}
};
var findInput = function ($form, attribute) {
var $input = $form.find(attribute.input);
if ($input.length && $input[0].tagName.toLowerCase() === 'div') {
// checkbox list or radio list
return $input.find('input');
} else {
return $input;
}
};
var watchAttributes = function ($form, attributes) { var watchAttributes = function ($form, attributes) {
$.each(attributes, function (i, attribute) { $.each(attributes, function (i, attribute) {
var $input = findInput($form, attribute); var $input = findInput($form, attribute);
...@@ -304,6 +284,9 @@ ...@@ -304,6 +284,9 @@
}); });
if (needAjaxValidation && (!data.submitting || $.isEmptyObject(messages))) { if (needAjaxValidation && (!data.submitting || $.isEmptyObject(messages))) {
// Perform ajax validation when at least one input needs it.
// If the validation is triggered by form submission, ajax validation
// should be done only when all inputs pass client validation
var $button = data.submitObject, var $button = data.submitObject,
extData = '&' + data.settings.ajaxVar + '=' + $form.attr('id'); extData = '&' + data.settings.ajaxVar + '=' + $form.attr('id');
if ($button && $button.length && $button.attr('name')) { if ($button && $button.length && $button.attr('name')) {
...@@ -389,4 +372,24 @@ ...@@ -389,4 +372,24 @@
} }
}; };
var getValue = function ($form, attribute) {
var $input = findInput($form, attribute);
var type = $input.attr('type');
if (type === 'checkbox' || type === 'radio') {
return $input.filter(':checked').val();
} else {
return $input.val();
}
};
var findInput = function ($form, attribute) {
var $input = $form.find(attribute.input);
if ($input.length && $input[0].tagName.toLowerCase() === 'div') {
// checkbox list or radio list
return $input.find('input');
} else {
return $input;
}
};
})(window.jQuery); })(window.jQuery);
\ No newline at end of file
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