增加功能:同步longbow.validate脚本

This commit is contained in:
Argo-MacBookPro 2018-11-21 16:19:14 +08:00 committed by Argo-Surface
parent 5dba365ce0
commit bf86754982
2 changed files with 18 additions and 14 deletions

View File

@ -16,7 +16,7 @@
return $("option:selected", element).length;
case "input":
if (this.checkable(element)) {
return this.findByName(element.name).filter(":checked").length;
return $(element).filter(":checked").length;
}
}
return value.length;
@ -38,12 +38,6 @@
return param(element);
}
},
findByName: function (name) {
return $('body').find("[name='" + this.escapeCssMeta(name) + "']");
},
escapeCssMeta: function (string) {
return string.replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1");
},
previousValue: function (element, method) {
method = typeof method === "string" && method || "remote";
return $.data(element, "previousValue") || $.data(element, "previousValue", {
@ -260,6 +254,10 @@
$.validator.addMethod("ip", function (value, element) {
return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/.test(value);
}, "请填写正确的IP地址");
$.validator.addMethod("radioGroup", function (value, element) {
return $(element).find(':checked').length === 1;
}, "请选择一个选项");
}
$('[data-toggle="LgbValidate"]').lgbValidate();
});

View File

@ -16,7 +16,7 @@
return $("option:selected", element).length;
case "input":
if (this.checkable(element)) {
return this.findByName(element.name).filter(":checked").length;
return $(element).filter(":checked").length;
}
}
return value.length;
@ -38,12 +38,6 @@
return param(element);
}
},
findByName: function (name) {
return $('body').find("[name='" + this.escapeCssMeta(name) + "']");
},
escapeCssMeta: function (string) {
return string.replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1");
},
previousValue: function (element, method) {
method = typeof method === "string" && method || "remote";
return $.data(element, "previousValue") || $.data(element, "previousValue", {
@ -86,6 +80,14 @@
},
settings: $.validator.defaults
}, this.defaults(), options);
// fix bug Edge
this.$element.find('select' + this.options.childClass).on('input', function (e) {
e.stopPropagation();
}).on('change', function () {
$(this).trigger('input.lgb.validate');
});
this.$element.on('input.lgb.validate', this.options.childClass, function () {
if (!that.validElement(this)) $(this).tooltip('show');
}).on('inserted.bs.tooltip', this.options.childClass, function () {
@ -258,6 +260,10 @@
$.validator.addMethod("ip", function (value, element) {
return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/.test(value);
}, "请填写正确的IP地址");
$.validator.addMethod("radioGroup", function (value, element) {
return $(element).find(':checked').length === 1;
}, "请选择一个选项");
}
$('[data-toggle="LgbValidate"]').lgbValidate();
});