Skip to content

Commit 5718866

Browse files
committed
add inputtype to numeric aliases RobinHerbots#2022
1 parent 08a12f0 commit 5718866

29 files changed

+171
-196
lines changed

CHANGELOG.md

+19-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [UNRELEASED]
44

5+
### Addition
6+
- numeric.extensions - add inputType option to specify the type of initial value
7+
- README_numeric.md => Setting initial values
8+
59
### Updates
610

711
### Fixed
@@ -35,7 +39,7 @@
3539
- Autofill corrupts input on email mask #1908(gl)
3640

3741
## [4.0.0 - 2018-05-26]
38-
### added
42+
### Addition
3943
- add support for beforeInput event with inputType (Input Events Level 2 - https://w3c.github.io/input-events/)
4044
- extend positionCaretOnClick with "ignore" to ignore the click in the input
4145
- jit enabled dynamic masks
@@ -101,8 +105,8 @@ while there are already many enhancements available.
101105
- Can't input character at the end if it's also a placeholder on Android #1648
102106

103107
## [3.3.8 - 2017-08-24]
104-
### added
105-
- added \uFF11-\uFF19 character range to 9 definition #1606
108+
### Addition
109+
- Addition \uFF11-\uFF19 character range to 9 definition #1606
106110
- importDataAttributes option #1633
107111
- add dot support in regex #1651
108112

@@ -125,7 +129,7 @@ while there are already many enhancements available.
125129
- Cannot delete after fill up all the mask Android Chrome browser Jsfiddle #1637
126130

127131
## [3.3.7 - 2017-06-09]
128-
### added
132+
### Addition
129133
- allow custom operation in casing option by callback #1565
130134

131135
### Updates
@@ -143,7 +147,7 @@ while there are already many enhancements available.
143147
- ndxInitializer.shift is not a function
144148

145149
## [3.3.6 - 2017-05-11]
146-
### added
150+
### Addition
147151
- noValuePatching option #1276
148152

149153
### Updates
@@ -164,7 +168,7 @@ while there are already many enhancements available.
164168
- 29 february of non leap-year #1567
165169

166170
## [3.3.5 - 2017-04-10]
167-
### Added
171+
### Addition
168172
- add example webpack setup (thx to Kevin Suen)
169173
- build-in regex support without extension (WIP)
170174

@@ -197,7 +201,7 @@ while there are already many enhancements available.
197201
- Form can`t submitted with input[name=disabled] #1473
198202

199203
## [3.3.4 - 2016-12-22]
200-
### Added
204+
### Addition
201205
- extra extension points: analyseMask
202206
- colorMask option ~ css styleable mask
203207

@@ -244,7 +248,7 @@ while there are already many enhancements available.
244248

245249
## [3.3.2 - 2016-09-09]
246250

247-
### Added
251+
### Addition
248252
- mask-level casing => #1352
249253
- 'casing': 'title' #1277
250254
- add quantifier syntax for digits option in numeric alias. #1374
@@ -294,7 +298,7 @@ while there are already many enhancements available.
294298

295299
## [3.3.0] - 2016-04-05
296300

297-
### Added
301+
### Addition
298302
- nullable option => switch to return the placeholder or null when nothing is entered
299303
- VIN mask #1199
300304

@@ -356,7 +360,7 @@ while there are already many enhancements available.
356360
- fixed "valids is not defined" error #1166
357361

358362
## [3.2.6] - 2016-01-25
359-
### Added
363+
### Addition
360364
- add jitMasking option
361365
- supportsInputType option
362366
- staticDefinitionSymbol (see readme)
@@ -420,7 +424,7 @@ while there are already many enhancements available.
420424

421425
## [3.2.3] - 2015-11-09
422426

423-
### Added
427+
### Addition
424428
- Inputmask.remove
425429
- inputmask.binding => automated inputmask binding for html attributes
426430
- Add tooltip option
@@ -449,7 +453,7 @@ while there are already many enhancements available.
449453

450454
## [3.2.1] - 2015-10-07
451455

452-
### Added
456+
### Addition
453457
- inputmask.dependencyLib.jquery
454458
- inputmask.dependencyLib.jqlite
455459

@@ -475,7 +479,7 @@ while there are already many enhancements available.
475479

476480
## [3.2.0] - 2015-09-04
477481

478-
### Added
482+
### Addition
479483
- add option command to set and retrieve options on an inputmask
480484
- dependencyLib wrapper around needed jQuery functionality
481485
- mac address alias #986
@@ -547,7 +551,7 @@ while there are already many enhancements available.
547551
- Script looping start when add '.' between decimal values #870 ('.' part)
548552

549553
## [3.1.63] - 2015-05-04
550-
### Added
554+
### Addition
551555
- Support for CommonJS (Browserify)
552556

553557
### Updates
@@ -569,7 +573,7 @@ while there are already many enhancements available.
569573
- Phone extention backspace problem #454
570574

571575
## [3.1.62] - 2015-03-26
572-
### Added
576+
### Addition
573577
- Numeric alias: add unmaskAsNumber option
574578
- import russian phone codes from inputmask-multi
575579
- enable masking the text content in a div

README_numeric.md

+36
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,39 @@ Be warned that using the unmaskAsNumber option together with jQuery.serialize wi
8181

8282

8383
[#1288]: https://github.com/RobinHerbots/jquery.inputmask/issues/1288
84+
85+
86+
### inputType
87+
Indicates whether the value passed for initialization is text or a number
88+
89+
Default: "text"
90+
91+
92+
### Setting initial values
93+
94+
When initializing the mask with a value, you need to take some rules into account.
95+
Depending of the option inputType the value will be interpreted as text or as a number.
96+
97+
When inputType is text, the symbol of the radixPoint must be correct. When using number the . (dot) is used as radixpoint.
98+
99+
Setting a number will always work when using vanilla javascript setters.
100+
101+
Example with komma (,) as radixpoint
102+
```
103+
/html
104+
<input name="npt" value="123456,789"/>
105+
106+
//js
107+
Inputmask("decimal", {
108+
radixPoint: ',',
109+
inputtype: "text"
110+
}).mask("input");
111+
112+
$("input").val("123456,789");
113+
$("input").val(123456.789); //this doesn't work because jQuery converts the number to a string
114+
before passing it along to the Inputmask.
115+
116+
document.getElementsByName("npt")[0].value = "123456,789";
117+
document.getElementsByName("npt")[0].value = 123456.789; //type number
118+
119+
```

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "inputmask",
3-
"version": "4.0.3-beta.3",
3+
"version": "4.0.3-beta.4",
44
"main": [
55
"./index.js",
66
"./css/inputmask.css"

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "robinherbots/inputmask",
33
"description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.",
4-
"version": "4.0.3-beta.3",
4+
"version": "4.0.3-beta.4",
55
"type": "library",
66
"keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
77
"homepage": "http://robinherbots.github.io/Inputmask",

dist/inputmask/bindings/inputmask.binding.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {

dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {

dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {

dist/inputmask/dependencyLibs/inputmask.dependencyLib.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {

dist/inputmask/global/window.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
if (typeof define === "function" && define.amd) define(function() {

dist/inputmask/inputmask.date.extensions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {

dist/inputmask/inputmask.extensions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {

dist/inputmask/inputmask.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {
@@ -1388,6 +1388,7 @@
13881388
return result;
13891389
}
13901390
function trackbackPositions(originalPos, newPos, fillOnly) {
1391+
console.log("trackbackPositions");
13911392
var result;
13921393
if (originalPos === undefined) {
13931394
for (originalPos = newPos - 1; originalPos > 0; originalPos--) {
@@ -1516,9 +1517,6 @@
15161517
tests.length < 2 || tests.length === 2 && tests[1].match.def === ""))) {}
15171518
return position;
15181519
}
1519-
function getBufferElement(position) {
1520-
return getMaskSet().validPositions[position] === undefined ? getPlaceholder(position) : getMaskSet().validPositions[position].input;
1521-
}
15221520
function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
15231521
if (event && $.isFunction(opts.onBeforeWrite)) {
15241522
var result = opts.onBeforeWrite.call(inputmask, event, buffer, caretPos, opts);

dist/inputmask/inputmask.numeric.extensions.js

+21-40
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {
@@ -129,6 +129,7 @@
129129
insertMode: true,
130130
autoUnmask: false,
131131
unmaskAsNumber: false,
132+
inputType: "text",
132133
inputmode: "numeric",
133134
preValidation: function(buffer, pos, c, isSelection, opts, maskset) {
134135
if (c === "-" || c === opts.negationSymbol.front) {
@@ -475,49 +476,29 @@
475476
},
476477
onBeforeMask: function(initialValue, opts) {
477478
opts.isNegative = undefined;
478-
if (typeof initialValue == "number" && opts.radixPoint !== "") {
479-
initialValue = initialValue.toString().replace(".", opts.radixPoint);
480-
}
481-
initialValue = initialValue.toString().charAt(initialValue.length - 1) === opts.radixPoint ? initialValue.toString().substr(0, initialValue.length - 1) : initialValue.toString();
482-
if (opts.radixPoint !== "" && isFinite(initialValue)) {
483-
var vs = initialValue.split("."), groupSize = opts.groupSeparator !== "" ? parseInt(opts.groupSize) : 0;
484-
if (vs.length === 2 && (vs[0].length > groupSize || vs[1].length > groupSize || vs[0].length <= groupSize && vs[1].length < groupSize)) {
485-
initialValue = initialValue.replace(".", opts.radixPoint);
486-
}
487-
}
488-
var kommaMatches = initialValue.match(/,/g);
489-
var dotMatches = initialValue.match(/\./g);
490-
if (dotMatches && kommaMatches) {
491-
if (dotMatches.length > kommaMatches.length) {
492-
initialValue = initialValue.replace(/\./g, "");
493-
initialValue = initialValue.replace(",", opts.radixPoint);
494-
} else if (kommaMatches.length > dotMatches.length) {
495-
initialValue = initialValue.replace(/,/g, "");
496-
initialValue = initialValue.replace(".", opts.radixPoint);
497-
} else {
498-
initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue.replace(/,/g, "");
499-
}
500-
} else {
501-
initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
479+
var radixPoint = opts.radixPoint || ",";
480+
if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") {
481+
initialValue = initialValue.toString().replace(".", radixPoint);
502482
}
483+
var valueParts = initialValue.split(radixPoint), integerPart = valueParts[0].replace(/[^\-0-9]/g, ""), decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "";
484+
initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
503485
var digits = 0;
504-
if (opts.radixPoint !== "" && initialValue.indexOf(opts.radixPoint) !== -1) {
505-
var valueParts = initialValue.split(opts.radixPoint), digits = valueParts[1].match(new RegExp("\\d*"))[0].length, digitsFactor = Math.pow(10, digits || 1);
506-
if (isFinite(opts.digits)) {
507-
digits = parseInt(opts.digits);
508-
digitsFactor = Math.pow(10, digits);
509-
}
510-
initialValue = initialValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
511-
if (isFinite(initialValue)) initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor;
512-
initialValue = initialValue.toString().replace(".", opts.radixPoint);
513-
}
514-
if (opts.digits === 0) {
515-
if (initialValue.indexOf(".") !== -1) {
516-
initialValue = initialValue.substring(0, initialValue.indexOf("."));
517-
} else if (initialValue.indexOf(",") !== -1) {
518-
initialValue = initialValue.substring(0, initialValue.indexOf(","));
486+
if (radixPoint !== "") {
487+
digits = decimalPart.length;
488+
if (decimalPart !== "") {
489+
var digitsFactor = Math.pow(10, digits || 1);
490+
if (isFinite(opts.digits)) {
491+
digits = parseInt(opts.digits);
492+
digitsFactor = Math.pow(10, digits);
493+
}
494+
initialValue = initialValue.replace(Inputmask.escapeRegex(radixPoint), ".");
495+
if (isFinite(initialValue)) initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor;
496+
initialValue = initialValue.toString().replace(".", radixPoint);
519497
}
520498
}
499+
if (opts.digits === 0 && initialValue.indexOf(Inputmask.escapeRegex(radixPoint)) !== -1) {
500+
initialValue = initialValue.substring(0, initialValue.indexOf(Inputmask.escapeRegex(radixPoint)));
501+
}
521502
return alignDigits(initialValue.toString().split(""), digits, opts).join("");
522503
},
523504
onKeyDown: function(e, buffer, caretPos, opts) {

dist/inputmask/jquery.inputmask.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://github.com/RobinHerbots/Inputmask
44
* Copyright (c) 2010 - 2018 Robin Herbots
55
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
6-
* Version: 4.0.3-beta.3
6+
* Version: 4.0.3-beta.4
77
*/
88

99
(function(factory) {

0 commit comments

Comments
 (0)