Browse Source

form wip

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
9fc4c3807b
  1. 49
      framework/assets/yii.activeForm.js

49
framework/assets/yii.activeForm.js

@ -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 @@
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 @@
}, },
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 @@
} }
}; };
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 @@
}); });
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 @@
} }
}; };
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);
Loading…
Cancel
Save