Browse Source

注册前端自定义验证器

jqh 5 years ago
parent
commit
8800011c08

+ 8 - 0
resources/assets/dcat-admin/main.js

@@ -400,6 +400,14 @@ window.require = window.define = window.exports = window.module = undefined;
             });
         };
 
+        // 注册自定义验证器
+        LA.extendValidator = function (rule, callback, message) {
+            var GLOBAL = $.fn.validator.Constructor.DEFAULTS;
+
+            GLOBAL.custom[rule] = callback;
+            GLOBAL.errors[rule] = message || null;
+        };
+
         function layer_position(idx, p) {
             switch (p) {
                 case 'rb':

File diff suppressed because it is too large
+ 0 - 0
resources/assets/dcat-admin/main.min.js


+ 3 - 4
src/Form/Field/Text.php

@@ -100,10 +100,9 @@ class Text extends Field
     {
         Admin::script(
             <<<'JS'
-$.fn.validator.Constructor.DEFAULTS.custom.maxlength = function ($el) {
-    var length = $el.attr('data-maxlength');
-    return $el.val().length > length;
-};
+LA.extendValidator('maxlength', function ($el) {
+    return $el.val().length > $el.attr('data-maxlength');
+});
 JS
         );
 

Some files were not shown because too many files changed in this diff