* Method that either format or unformat the value of another element. * * - Format and return the given value, or set the formatted value into the given DOM element if one is passed as an argument. * - Unformat and return the raw numeric string corresponding to the given value, or dir
(isFormatting, valueOrStringOrElement, optionOverride = null)
| 2916 | * @private |
| 2917 | */ |
| 2918 | _formatOrUnformatOther(isFormatting, valueOrStringOrElement, optionOverride = null) { //FIXME test this |
| 2919 | // If the user wants to override the current element settings temporarily |
| 2920 | let settingsToUse; |
| 2921 | if (!AutoNumericHelper.isNull(optionOverride)) { |
| 2922 | settingsToUse = this._cloneAndMergeSettings(optionOverride); |
| 2923 | } else { |
| 2924 | settingsToUse = this.settings; |
| 2925 | } |
| 2926 | |
| 2927 | // Then the unformatting is done... |
| 2928 | let result; |
| 2929 | if (AutoNumericHelper.isElement(valueOrStringOrElement)) { |
| 2930 | // ...either directly on the DOM element value |
| 2931 | const elementValue = AutoNumericHelper.getElementValue(valueOrStringOrElement); |
| 2932 | if (isFormatting) { |
| 2933 | result = AutoNumeric.format(elementValue, settingsToUse); |
| 2934 | } |
| 2935 | else { |
| 2936 | result = AutoNumeric.unformat(elementValue, settingsToUse); |
| 2937 | } |
| 2938 | |
| 2939 | AutoNumericHelper.setElementValue(valueOrStringOrElement, result); //TODO Use `unformatAndSet` and `formatAndSet`instead |
| 2940 | |
| 2941 | return null; |
| 2942 | } |
| 2943 | |
| 2944 | // ...or on the given value |
| 2945 | if (isFormatting) { |
| 2946 | result = AutoNumeric.format(valueOrStringOrElement, settingsToUse); |
| 2947 | } |
| 2948 | else { |
| 2949 | result = AutoNumeric.unformat(valueOrStringOrElement, settingsToUse); |
| 2950 | } |
| 2951 | |
| 2952 | return result; |
| 2953 | } |
| 2954 | |
| 2955 | /** |
| 2956 | * Use the current AutoNumeric element settings to initialize the DOM element(s) given as a parameter. |
no test coverage detected