增加功能:同步longbow.validate脚本
This commit is contained in:
parent
5dba365ce0
commit
bf86754982
|
@ -16,7 +16,7 @@
|
||||||
return $("option:selected", element).length;
|
return $("option:selected", element).length;
|
||||||
case "input":
|
case "input":
|
||||||
if (this.checkable(element)) {
|
if (this.checkable(element)) {
|
||||||
return this.findByName(element.name).filter(":checked").length;
|
return $(element).filter(":checked").length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value.length;
|
return value.length;
|
||||||
|
@ -38,12 +38,6 @@
|
||||||
return param(element);
|
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) {
|
previousValue: function (element, method) {
|
||||||
method = typeof method === "string" && method || "remote";
|
method = typeof method === "string" && method || "remote";
|
||||||
return $.data(element, "previousValue") || $.data(element, "previousValue", {
|
return $.data(element, "previousValue") || $.data(element, "previousValue", {
|
||||||
|
@ -260,6 +254,10 @@
|
||||||
$.validator.addMethod("ip", function (value, element) {
|
$.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);
|
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地址");
|
}, "请填写正确的IP地址");
|
||||||
|
|
||||||
|
$.validator.addMethod("radioGroup", function (value, element) {
|
||||||
|
return $(element).find(':checked').length === 1;
|
||||||
|
}, "请选择一个选项");
|
||||||
}
|
}
|
||||||
$('[data-toggle="LgbValidate"]').lgbValidate();
|
$('[data-toggle="LgbValidate"]').lgbValidate();
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
return $("option:selected", element).length;
|
return $("option:selected", element).length;
|
||||||
case "input":
|
case "input":
|
||||||
if (this.checkable(element)) {
|
if (this.checkable(element)) {
|
||||||
return this.findByName(element.name).filter(":checked").length;
|
return $(element).filter(":checked").length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value.length;
|
return value.length;
|
||||||
|
@ -38,12 +38,6 @@
|
||||||
return param(element);
|
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) {
|
previousValue: function (element, method) {
|
||||||
method = typeof method === "string" && method || "remote";
|
method = typeof method === "string" && method || "remote";
|
||||||
return $.data(element, "previousValue") || $.data(element, "previousValue", {
|
return $.data(element, "previousValue") || $.data(element, "previousValue", {
|
||||||
|
@ -86,6 +80,14 @@
|
||||||
},
|
},
|
||||||
settings: $.validator.defaults
|
settings: $.validator.defaults
|
||||||
}, this.defaults(), options);
|
}, 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 () {
|
this.$element.on('input.lgb.validate', this.options.childClass, function () {
|
||||||
if (!that.validElement(this)) $(this).tooltip('show');
|
if (!that.validElement(this)) $(this).tooltip('show');
|
||||||
}).on('inserted.bs.tooltip', this.options.childClass, function () {
|
}).on('inserted.bs.tooltip', this.options.childClass, function () {
|
||||||
|
@ -258,6 +260,10 @@
|
||||||
$.validator.addMethod("ip", function (value, element) {
|
$.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);
|
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地址");
|
}, "请填写正确的IP地址");
|
||||||
|
|
||||||
|
$.validator.addMethod("radioGroup", function (value, element) {
|
||||||
|
return $(element).find(':checked').length === 1;
|
||||||
|
}, "请选择一个选项");
|
||||||
}
|
}
|
||||||
$('[data-toggle="LgbValidate"]').lgbValidate();
|
$('[data-toggle="LgbValidate"]').lgbValidate();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue