* Handler for 'focusout' events * On focusout, multiple things happens : * - The element value is formatted back if the `Alt` key was pressed, * - The element value is formatted back if `showOnlyNumbersOnFocus` was set to only show numbers, * - The element value is multiplied by
(e)
| 6956 | * @param {Event} e |
| 6957 | */ |
| 6958 | _onFocusOutAndMouseLeave(e) { |
| 6959 | //TODO Create separate handlers for blur and mouseleave |
| 6960 | this.isEditing = false; // Just in case no `keyUp` event have been sent (if the user lost the focus on the window while typing) |
| 6961 | |
| 6962 | if (e.type === 'mouseleave' && this.formulaMode) { |
| 6963 | return; |
| 6964 | } |
| 6965 | |
| 6966 | //FIXME Do not call `set()` if the current raw value is the same as the one we are trying to set (currently, on focus out, `set()` is always called, even if the value has not changed |
| 6967 | if (this.settings.unformatOnHover && e.type === 'mouseleave' && this.hoveredWithAlt) { |
| 6968 | this.constructor._reformatAltHovered(this); |
| 6969 | |
| 6970 | return; |
| 6971 | } |
| 6972 | |
| 6973 | if ((e.type === 'mouseleave' && !this.isFocused) || e.type === 'blur') { |
| 6974 | if (e.type === 'blur' && this.formulaMode) { |
| 6975 | this._exitFormulaMode(); |
| 6976 | } |
| 6977 | |
| 6978 | this._saveValueToPersistentStorage(); |
| 6979 | if (this.settings.showOnlyNumbersOnFocus === AutoNumeric.options.showOnlyNumbersOnFocus.onlyNumbers) { |
| 6980 | this.settings.digitGroupSeparator = this.originalDigitGroupSeparator; |
| 6981 | this.settings.currencySymbol = this.originalCurrencySymbol; |
| 6982 | this.settings.suffixText = this.originalSuffixText; |
| 6983 | } |
| 6984 | |
| 6985 | // Use the rawValue, multiplied by `rawValueDivisor` if defined |
| 6986 | const rawValueToFormat = this._getRawValueToFormat(this.rawValue); |
| 6987 | const isRawValueNull = AutoNumericHelper.isNull(rawValueToFormat); |
| 6988 | const [minTest, maxTest] = this.constructor._checkIfInRangeWithOverrideOption(rawValueToFormat, this.settings); |
| 6989 | |
| 6990 | // Directly set the formatted value if the `rawValue` is found in `valuesToStrings` |
| 6991 | let elementValueIsAlreadySet = false; |
| 6992 | if (rawValueToFormat !== '' && !isRawValueNull) { |
| 6993 | this._triggerRangeEvents(minTest, maxTest); |
| 6994 | |
| 6995 | if (this.settings.valuesToStrings && this._checkValuesToStrings(rawValueToFormat)) { |
| 6996 | // Set the formatted value with the corresponding string |
| 6997 | this._setElementValue(this.settings.valuesToStrings[rawValueToFormat]); |
| 6998 | elementValueIsAlreadySet = true; |
| 6999 | } |
| 7000 | } |
| 7001 | |
| 7002 | // Only generate the formatted value if no `valuesToStrings` have been found |
| 7003 | if (!elementValueIsAlreadySet) { |
| 7004 | let value; |
| 7005 | if (isRawValueNull || rawValueToFormat === '') { |
| 7006 | value = rawValueToFormat; |
| 7007 | } else { |
| 7008 | value = String(rawValueToFormat); |
| 7009 | } |
| 7010 | |
| 7011 | if (rawValueToFormat !== '' && !isRawValueNull) { |
| 7012 | if (minTest && maxTest && !this.constructor._isElementValueEmptyOrOnlyTheNegativeSign(rawValueToFormat, this.settings)) { |
| 7013 | value = this._modifyNegativeSignAndDecimalCharacterForRawValue(value); |
| 7014 | |
| 7015 | if (this.settings.divisorWhenUnfocused && !AutoNumericHelper.isNull(value)) { |
no test coverage detected