Browse Source

added setvalue function which triggers formatting when setting a value programatically
$(selector).inputmask('setvalue', '23031973');

Robin Herbots 15 years ago
parent
commit
f0a9f2f92f
1 changed files with 12 additions and 2 deletions
  1. 12 2
      jquery.inputmask.js

+ 12 - 2
jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 0.0.5
+Version: 0.0.6
    
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
@@ -73,7 +73,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 });
             } else if (fn == 'unmaskedvalue') {
                 return unmaskedvalue($(this));
-            } else { //maybe fn is a mask so we try
+            } else if (fn == 'setvalue') {
+                return setvalue($(this), options);
+            } 
+            else { //maybe fn is a mask so we try
                 //set mask
                 opts.mask = fn;
 
@@ -150,6 +153,13 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             }
         }
 
+		function setvalue(el, value) {
+		    var pasteEventName = $.browser.msie ? 'paste' : 'input';
+            el.val(value).trigger(pasteEventName);
+            el.blur();
+            return el;
+        }
+
         function mask(el) {
             var input = $(el);
             //store tests in the input element - used to get the unmasked value