From bf86754982c4aaa2645c1ebf8338b5463e582fbf Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Wed, 21 Nov 2018 16:19:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E5=90=8C=E6=AD=A5longbow.validate=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/js/longbow.validate.js | 12 +++++------ .../wwwroot/js/longbow.validate.js | 20 ++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Bootstrap.Admin/wwwroot/js/longbow.validate.js b/Bootstrap.Admin/wwwroot/js/longbow.validate.js index a084f860..f06c0a3c 100644 --- a/Bootstrap.Admin/wwwroot/js/longbow.validate.js +++ b/Bootstrap.Admin/wwwroot/js/longbow.validate.js @@ -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(); }); diff --git a/Bootstrap.Client/wwwroot/js/longbow.validate.js b/Bootstrap.Client/wwwroot/js/longbow.validate.js index 816caca5..7f82352a 100644 --- a/Bootstrap.Client/wwwroot/js/longbow.validate.js +++ b/Bootstrap.Client/wwwroot/js/longbow.validate.js @@ -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(); });