var validateFields = {
validType: [vEmpty, vLength, vCheck, vFloat, vRange, vEmail],
preNotValidCtl: undefined,
preNotValidType: undefined,
validateAll: function() {
this.preNotValidCtl = undefined;
this.preNotValidType = undefined;
var base = this;
$(".validErr").removeClass("validErr");
for (var idx = 0, count = this.validType.length; idx < count; idx++) {
var validator = this.validType[idx];
$("." + validator.name).each(function() {
var $ctl = $(this);
if ($ctl.parent().is(":visible")) {
if (!validator.vd($ctl)) {
($ctl.attr("type") == "hidden") ?
$ctl.parent().addClass("validErr") : $ctl.addClass("validErr");
base.preNotValidType = validator;
base.preNotValidCtl = $ctl;
base.showWarning(validator, $ctl);
return false;
}
}
});
if (this.preNotValidCtl) {
break;
}
}
return this.preNotValidCtl == undefined;
},
showWarning: function(validator, $ctl) {
// 元件本身有設定錯誤訊息
var warning = "問題:" + validateFields.preNotValidType.warning + "\n";
var conditions = [];
for (var idx = 0, count = validateFields.validType.length; idx < count; idx++) {
var ov = validateFields.validType[idx];
if (ov.name != validator.name) {
if ($ctl.hasClass(ov.name)) {
ov.vd($ctl);
conditions.push(ov.getWarning($ctl));
}
}
}
if (conditions.length > 0) {
warning += "\n其它限制:" + conditions.join("、");
}
alert(warning);
if ($ctl.attr("type") == "hidden") {
if ($ctl.parent()) {
$ctl.parent().focus();
}
}
else if (!$ctl.is(":hidden")) {
$ctl.focus();
}
}
};