* Returns the unformatted value, but following the `outputFormat` setting, which means the output can either be : * - a string (that could or could not represent a number (i.e. "12345,67-")), or * - a plain number (if the setting 'number' is used). * * By default, the returned va
(forcedOutputFormat = null, callback = null)
| 2554 | * @returns {*} |
| 2555 | */ |
| 2556 | getLocalized(forcedOutputFormat = null, callback = null) { |
| 2557 | // First, check if only a callback has been passed, and if so, sanitize the parameters |
| 2558 | if (AutoNumericHelper.isFunction(forcedOutputFormat) && AutoNumericHelper.isNull(callback)) { |
| 2559 | callback = forcedOutputFormat; |
| 2560 | forcedOutputFormat = null; |
| 2561 | } |
| 2562 | |
| 2563 | // Then get the localized value |
| 2564 | let value; |
| 2565 | if (AutoNumericHelper.isEmptyString(this.rawValue)) { |
| 2566 | value = ''; |
| 2567 | } else { |
| 2568 | // Here I use `this.rawValue` instead of `this.getNumericString()` since the current input value could be unformatted with a localization (i.e. '1234567,89-'). |
| 2569 | // I also convert the rawValue to a number, then back to a string in order to drop the decimal part if the rawValue is an integer. |
| 2570 | value = ''+Number(this.rawValue); |
| 2571 | } |
| 2572 | |
| 2573 | if (value !== '' && Number(value) === 0 && this.settings.leadingZero !== AutoNumeric.options.leadingZero.keep) { |
| 2574 | value = '0'; |
| 2575 | } |
| 2576 | |
| 2577 | let outputFormatToUse; |
| 2578 | if (AutoNumericHelper.isNull(forcedOutputFormat)) { |
| 2579 | outputFormatToUse = this.settings.outputFormat; |
| 2580 | } else { |
| 2581 | outputFormatToUse = forcedOutputFormat; |
| 2582 | } |
| 2583 | |
| 2584 | const result = this.constructor._toLocale(value, outputFormatToUse, this.settings); |
| 2585 | this._executeCallback(result, callback); |
| 2586 | |
| 2587 | return result; |
| 2588 | } |
| 2589 | |
| 2590 | /** |
| 2591 | * Force the element to reformat its value again (just in case the formatting has been lost). |
no test coverage detected