Browse Source

Update autocompletion for numbers

Robin Herbots 13 years ago
parent
commit
e466c510ed
3 changed files with 38 additions and 31 deletions
  1. 19 16
      README.md
  2. 16 14
      js/jquery.inputmask.extentions.js
  3. 3 1
      js/jquery.inputmask.js

+ 19 - 16
README.md

@@ -46,7 +46,7 @@ Example of some new definitions:
 insertMode: false
 ```
 
-These allow for a finer date validation then 99/99/9999 which also allows 33/33/3333 for example.  
+These allow for a finer date validation then 99/99/9999 which also allows 33/33/3333 for example. 
 In the jquery.inputmask.extentions.js you find a full date input validation which takes days, months & leap years into account.
 
 Also extra features like mask-repetitions (greedy and non-gready) and many other additions are included.  In the examples you will find more about them.
@@ -215,14 +215,6 @@ While the field has focus and is blank, users will see the full mask `___-___`.
 When the required part of the mask is filled and the field loses focus, the user will see `123`.
 When both the required and optional parts of the mask are filled out and the field loses focus, the user will see `123-abc`.
 
-### oncleared option
-
-```javascript
-$(document).ready(function(){
-    $("#ssn").inputmask("999-99-9999",{placeholder:" ", oncleared: function(){ alert('Set focus somewhere else ;-)');} });
-});
-```
-
 ### aliases option
 
 First you have to create an alias definition (more examples can be found in jquery.inputmask.extentions.js)
@@ -276,6 +268,15 @@ $(document).ready(function(){
 });
 ```
 
+### onKeyUp / onKeyDown option
+
+Use this to do some extra processing of the input when certain keys are pressed.
+This can be usefull when implementing an alias, ex. decimal alias, autofill the digits when pressing tab.
+
+see jquery.inputmask.extentions.js for some examples
+
+
+## Markup options
 ### RTL input 
 
 Just add the dir="rtl" attribute to the input element
@@ -284,14 +285,16 @@ Just add the dir="rtl" attribute to the input element
 <input id="test" dir="rtl" />
 ```
 
-### onKeyUp option
-
-Use this to do some extra processing of the input when certain keys are pressed.  
-This can be usefull when implementing an alias, ex. decimal alias, autofill the digits when pressing tab.
-
-see jquery.inputmask.extentions.js for some examples
 
 ## Compiling with Google Closure Compiler
 
 First grab the sources from github.  In the root you type ant.
-A new folder dist is created with the minified and optimized js-files
+A new folder dist is created with the minified and optimized js-files
+
+# jquery.inputmask extentions
+
+## Alias definitions
+
+### date aliases
+
+### numeric aliases

+ 16 - 14
js/jquery.inputmask.extentions.js

@@ -3,7 +3,7 @@ Input Mask plugin extentions
 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.7
+Version: 0.0.8
 
 Optional extentions on the jquery.inputmask base
 */
@@ -56,6 +56,7 @@ Optional extentions on the jquery.inputmask base
                 monthpre: new RegExp("[01]"),
                 month: new RegExp("((0[1-9]|[12][0-9])\/(0[1-9]|1[012]))|(30\/(0[13-9]|1[012]))|(31\/(0[13578]|1[02]))"),
 				yearpre1: new RegExp("[12]"),                
+				yearpre3: new RegExp("(19|20)\\d"),
                 year: new RegExp("(19|20)\\d{2}"),
                 daypre: new RegExp("[0-3]"),
                 day: new RegExp("0[1-9]|[12][0-9]|3[01]")
@@ -63,10 +64,7 @@ Optional extentions on the jquery.inputmask base
             leapday: "29/02/",
             onKeyUp: function(e, opts) {
                                 var $input = $(this), input = this;
-                                if (e.keyCode == opts.keyCode.TAB) {
-                                    var nptStr = input._valueGet();
-                                    //do stuff
-                                } else if(e.ctrlKey && e.keyCode == opts.keyCode.RIGHT){
+                                if(e.ctrlKey && e.keyCode == opts.keyCode.RIGHT){
                                 	var today = new Date();
                                 	$input.val(today.getDate().toString() + (today.getMonth()+1).toString() + today.getFullYear().toString());
                                 }
@@ -159,7 +157,7 @@ Optional extentions on the jquery.inputmask base
                             	if (!strict && !isValid) {
                                 	var yearPrefix = (new Date()).getFullYear().toString().slice(0,2);
 
-                            	    isValid = opts.regex.yearpre1.test(yearPrefix + chrs);
+                            	    isValid = opts.regex.yearpre3.test(yearPrefix + chrs);
                         	        if (isValid) {
                     	                buffer[pos++] = yearPrefix[0];
                 	                    buffer[pos++] = yearPrefix[1];
@@ -185,16 +183,14 @@ Optional extentions on the jquery.inputmask base
                         daypre: new RegExp("((0[13-9]|1[012])\/[0-3])|(02\/[0-2])"),
                         month: new RegExp("0[1-9]|1[012]"),
                         monthpre: new RegExp("[01]"),
-                        yearpre1: new RegExp("[12]"),                
+                        yearpre1: new RegExp("[12]"),
+                        yearpre3: new RegExp("(19|20)\\d"),                 
                         year: new RegExp("(19|20)\\d{2}")
                     },
                     leapday: "02/29/",
                     onKeyUp: function(e, opts) {
                                 var $input = $(this), input = this;
-                                if (e.keyCode == opts.keyCode.TAB) {
-                                    var nptStr = input._valueGet();
-                                    //do stuff
-                                } else if(e.ctrlKey && e.keyCode == opts.keyCode.RIGHT){
+                                if(e.ctrlKey && e.keyCode == opts.keyCode.RIGHT){
                                 	var today = new Date();
                                 	$input.val((today.getMonth()+1).toString() + today.getDate().toString() + today.getFullYear().toString());
                                 }
@@ -288,7 +284,7 @@ Optional extentions on the jquery.inputmask base
                             	if (!strict && !isValid) {
                                 	var yearPrefix = (new Date()).getFullYear().toString().slice(0,2);
 
-                            	    isValid = opts.regex.yearpre1.test(yearPrefix + chrs);
+                            	    isValid = opts.regex.yearpre3.test(yearPrefix + chrs);
                         	        if (isValid) {
                     	                buffer[pos++] = yearPrefix[0];
                 	                    buffer[pos++] = yearPrefix[1];
@@ -340,11 +336,17 @@ Optional extentions on the jquery.inputmask base
                             regex: {
                                 number: function(radixPoint, digits) { return new RegExp("^[\+\\d\-]{1}\\d*[" + radixPoint + "]?\\d" + digits + "$"); }
                             },
-                            onKeyUp: function(e, opts) {
+                            onKeyDown: function(e, opts) {
                                 var $input = $(this), input = this;
                                 if (e.keyCode == opts.keyCode.TAB) {
                                     var nptStr = input._valueGet();
-                                    //do stuff
+                                    var radixPosition = nptStr.indexOf(opts.radixPoint[opts.radixPoint.length -1]);
+                                    if(radixPosition != -1){
+                                    	for(var i = 1; i < opts.digits; i++) {
+                                    		if(nptStr[radixPosition + i]) nptStr = nptStr + "0";  
+                                    	}
+                                    	$input.val(nptStr);
+                                    }
                                 }
                             },
                             definitions: {

+ 3 - 1
js/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.6.0b
+Version: 0.6.1
  
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
@@ -32,6 +32,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 clearIncomplete: false, //clear the incomplete input on blur
                 aliases: {}, //aliases definitions => see jquery.inputmask.extentions.js
                 onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
+                onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
                 definitions: {
                     '9': {
                         validator: "[0-9]",
@@ -809,6 +810,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                         }
                     }
 
+					opts.onKeyDown.call(this, e, opts); //extra stuff todo on keydown
                     ignorable = $.inArray(k, opts.ignorables) != -1;
                 }