浏览代码

fix maxlength

Robin Herbots 12 年之前
父节点
当前提交
96be98c64c
共有 1 个文件被更改,包括 6 次插入25 次删除
  1. 6 25
      js/jquery.inputmask.js

+ 6 - 25
js/jquery.inputmask.js

@@ -671,6 +671,7 @@
             }
 
             function getMaskLength() {
+				var maxLength = $el.prop('maxLength'), maskLength;
                 if (!getActiveMaskSet()['greedy']) {
                     var lvp = getLastValidPosition() + 1,
                         test = getActiveTest(lvp);
@@ -678,9 +679,11 @@
                         var tests = getActiveTests(++lvp);
                         test = tests[tests.length - 1];
                     }
-                    return getMaskTemplate(false, lvp)["mask"].length;
-                }
-                return getActiveBuffer().length;
+                    maskLength = getMaskTemplate(false, lvp)["mask"].length;
+                } else
+					maskLength = getActiveBuffer().length;
+					
+				return maskLength < maxLength && maxLength > -1 /* FF sets no defined max length to -1 */ ? maskLength : maxLength;
             }
 
             //pos: from position
@@ -1445,28 +1448,6 @@
                     //correct greedy setting if needed
                     getActiveMaskSet()['greedy'] = getActiveMaskSet()['greedy'] ? getActiveMaskSet()['greedy'] : getActiveMaskSet()['repeat'] == 0;
 
-                    //handle maxlength attribute
-                    if ($el.attr("maxLength") != null) //only when the attribute is set
-                    {
-                        var maxLength = $el.prop('maxLength');
-                        if (maxLength > -1) { //handle *-repeat
-                            $.each(masksets, function (ndx, ms) {
-                                if (typeof (ms) == "object") {
-                                    if (ms["repeat"] == "*") {
-                                        ms["repeat"] = maxLength;
-                                    }
-                                }
-                            });
-                        }
-                        if (getMaskLength() >= maxLength && maxLength > -1) { //FF sets no defined max length to -1 
-                            if (maxLength < getActiveBufferTemplate().length) getActiveBufferTemplate().length = maxLength;
-                            if (getActiveMaskSet()['greedy'] == false) {
-                                getActiveMaskSet()['repeat'] = Math.round(maxLength / getActiveBufferTemplate().length);
-                            }
-                            $el.prop('maxLength', getMaskLength() * 2);
-                        }
-                    }
-
                     patchValueProperty(el);
 
                     if (opts.numericInput) opts.isNumeric = opts.numericInput;