|
3 | 3 | * https://github.com/RobinHerbots/Inputmask
|
4 | 4 | * Copyright (c) 2010 - 2018 Robin Herbots
|
5 | 5 | * 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 |
7 | 7 | */
|
8 | 8 |
|
9 | 9 | (function(factory) {
|
|
129 | 129 | insertMode: true,
|
130 | 130 | autoUnmask: false,
|
131 | 131 | unmaskAsNumber: false,
|
| 132 | + inputType: "text", |
132 | 133 | inputmode: "numeric",
|
133 | 134 | preValidation: function(buffer, pos, c, isSelection, opts, maskset) {
|
134 | 135 | if (c === "-" || c === opts.negationSymbol.front) {
|
|
475 | 476 | },
|
476 | 477 | onBeforeMask: function(initialValue, opts) {
|
477 | 478 | 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); |
502 | 482 | }
|
| 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); |
503 | 485 | 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); |
519 | 497 | }
|
520 | 498 | }
|
| 499 | + if (opts.digits === 0 && initialValue.indexOf(Inputmask.escapeRegex(radixPoint)) !== -1) { |
| 500 | + initialValue = initialValue.substring(0, initialValue.indexOf(Inputmask.escapeRegex(radixPoint))); |
| 501 | + } |
521 | 502 | return alignDigits(initialValue.toString().split(""), digits, opts).join("");
|
522 | 503 | },
|
523 | 504 | onKeyDown: function(e, buffer, caretPos, opts) {
|
|
0 commit comments