MCPcopy
hub / github.com/autoNumeric/autoNumeric / _onFocusOutAndMouseLeave

Method _onFocusOutAndMouseLeave

src/AutoNumeric.js:6958–7073  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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)) {

Callers 1

_createEventListenersMethod · 0.95

Calls 15

_exitFormulaModeMethod · 0.95
_getRawValueToFormatMethod · 0.95
_triggerRangeEventsMethod · 0.95
_checkValuesToStringsMethod · 0.95
_setElementValueMethod · 0.95
_setRawValueMethod · 0.95
_onBlurMethod · 0.95
_reformatAltHoveredMethod · 0.80
isNullMethod · 0.80

Tested by

no test coverage detected