Browse Source

add undoOnEscape option

Robin Herbots 11 years ago
parent
commit
bbb7fbacc9

+ 4 - 0
README.md

@@ -624,6 +624,10 @@ $(document).ready(function(){
     $(selector).inputmask('decimal', { rightAlign: false });  //disables the right alignment of the decimal input
 });
 ```
+#### undoOnEscape
+Make escape behave like undo. (ctrl-Z)  
+Pressing escape reverts the value to the value before focus.  
+Default: true 
 
 #### radixPoint
 

+ 2 - 1
dist/inputmask/jquery.inputmask.js

@@ -749,7 +749,7 @@
             opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() {
                 var caretPos = seekNext(getLastValidPosition());
                 opts.insertMode || caretPos != getMaskLength() || e.shiftKey || caretPos--, caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
-            }, 0) : k == $.inputmask.keyCode.HOME && !e.shiftKey || k == $.inputmask.keyCode.PAGE_UP ? caret(input, 0, e.shiftKey ? pos.begin : 0) : k == $.inputmask.keyCode.ESCAPE || 90 == k && e.ctrlKey ? (checkVal(input, !0, !1, valueOnFocus.split("")), 
+            }, 0) : k == $.inputmask.keyCode.HOME && !e.shiftKey || k == $.inputmask.keyCode.PAGE_UP ? caret(input, 0, e.shiftKey ? pos.begin : 0) : opts.undoOnEscape && k == $.inputmask.keyCode.ESCAPE || 90 == k && e.ctrlKey ? (checkVal(input, !0, !1, valueOnFocus.split("")), 
             $input.click()) : k != $.inputmask.keyCode.INSERT || e.shiftKey || e.ctrlKey ? 0 != opts.insertMode || e.shiftKey || (k == $.inputmask.keyCode.RIGHT ? setTimeout(function() {
                 var caretPos = caret(input);
                 caret(input, caretPos.begin);
@@ -1060,6 +1060,7 @@
                 showTooltip: !1,
                 numericInput: !1,
                 rightAlign: !1,
+                undoOnEscape: !0,
                 radixPoint: "",
                 radixFocus: !1,
                 nojumps: !1,

+ 2 - 1
dist/jquery.inputmask.bundle.js

@@ -747,7 +747,7 @@
             opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() {
                 var caretPos = seekNext(getLastValidPosition());
                 opts.insertMode || caretPos != getMaskLength() || e.shiftKey || caretPos--, caret(input, e.shiftKey ? pos.begin : caretPos, caretPos);
-            }, 0) : k == $.inputmask.keyCode.HOME && !e.shiftKey || k == $.inputmask.keyCode.PAGE_UP ? caret(input, 0, e.shiftKey ? pos.begin : 0) : k == $.inputmask.keyCode.ESCAPE || 90 == k && e.ctrlKey ? (checkVal(input, !0, !1, valueOnFocus.split("")), 
+            }, 0) : k == $.inputmask.keyCode.HOME && !e.shiftKey || k == $.inputmask.keyCode.PAGE_UP ? caret(input, 0, e.shiftKey ? pos.begin : 0) : opts.undoOnEscape && k == $.inputmask.keyCode.ESCAPE || 90 == k && e.ctrlKey ? (checkVal(input, !0, !1, valueOnFocus.split("")), 
             $input.click()) : k != $.inputmask.keyCode.INSERT || e.shiftKey || e.ctrlKey ? 0 != opts.insertMode || e.shiftKey || (k == $.inputmask.keyCode.RIGHT ? setTimeout(function() {
                 var caretPos = caret(input);
                 caret(input, caretPos.begin);
@@ -1058,6 +1058,7 @@
                 showTooltip: !1,
                 numericInput: !1,
                 rightAlign: !1,
+                undoOnEscape: !0,
                 radixPoint: "",
                 radixFocus: !1,
                 nojumps: !1,

File diff suppressed because it is too large
+ 1 - 1
dist/jquery.inputmask.bundle.min.js


+ 2 - 1
js/jquery.inputmask.js

@@ -1336,7 +1336,7 @@
                     }, 0);
                 } else if ((k == $.inputmask.keyCode.HOME && !e.shiftKey) || k == $.inputmask.keyCode.PAGE_UP) { //Home or page_up
                     caret(input, 0, e.shiftKey ? pos.begin : 0);
-                } else if (k == $.inputmask.keyCode.ESCAPE || (k == 90 && e.ctrlKey)) { //escape && undo
+                } else if ((opts.undoOnEscape && k == $.inputmask.keyCode.ESCAPE) || (k == 90 && e.ctrlKey)) { //escape && undo
                     checkVal(input, true, false, valueOnFocus.split(''));
                     $input.click();
                 } else if (k == $.inputmask.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) { //insert
@@ -1911,6 +1911,7 @@
                 showTooltip: false, //show the activemask as tooltip
                 numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
                 rightAlign: false, //align to the right
+                undoOnEscape: true, //pressing escape reverts the value to the value before focus
                 //numeric basic properties
                 radixPoint: "", //".", // | ","
                 radixFocus: false, //position caret to radixpoint on initial click