* Select only the integer part in the formatted element content, whatever the value of `selectNumberOnly` * * @returns {AutoNumeric}
()
| 2729 | * @returns {AutoNumeric} |
| 2730 | */ |
| 2731 | selectInteger() { |
| 2732 | let start = 0; |
| 2733 | const isPositive = this.rawValue >= 0; |
| 2734 | |
| 2735 | // Negative or positive sign, if any |
| 2736 | if (this.settings.currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.prefix || |
| 2737 | (this.settings.currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.suffix && |
| 2738 | (this.settings.negativePositiveSignPlacement === AutoNumeric.options.negativePositiveSignPlacement.prefix || |
| 2739 | this.settings.negativePositiveSignPlacement === AutoNumeric.options.negativePositiveSignPlacement.none))) { |
| 2740 | if ((this.settings.showPositiveSign && isPositive) || // This only exclude the positive sign from being selected |
| 2741 | (!isPositive && this.settings.currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.prefix && this.settings.negativePositiveSignPlacement === AutoNumeric.options.negativePositiveSignPlacement.left)) { // And this excludes the negative sign from being selected in this special case : '-€ 1.234,57suffixText' |
| 2742 | start = start + 1; |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | // Currency symbol |
| 2747 | if (this.settings.currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.prefix) { |
| 2748 | start = start + this.settings.currencySymbol.length; |
| 2749 | } |
| 2750 | |
| 2751 | // Calculate the selection end position |
| 2752 | const elementValue = AutoNumericHelper.getElementValue(this.domElement); |
| 2753 | let end = elementValue.indexOf(this.settings.decimalCharacter); |
| 2754 | if (end === -1) { |
| 2755 | // No decimal character found |
| 2756 | if (this.settings.currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.suffix) { |
| 2757 | end = elementValue.length - this.settings.currencySymbol.length; |
| 2758 | } else { |
| 2759 | end = elementValue.length; |
| 2760 | } |
| 2761 | |
| 2762 | // Trailing negative sign |
| 2763 | if (!isPositive && |
| 2764 | (this.settings.negativePositiveSignPlacement === AutoNumeric.options.negativePositiveSignPlacement.suffix || |
| 2765 | this.settings.currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.suffix)) { |
| 2766 | end = end - 1; |
| 2767 | } |
| 2768 | |
| 2769 | // Avoid selecting the suffix test |
| 2770 | end = end - this.settings.suffixText.length; |
| 2771 | } |
| 2772 | |
| 2773 | AutoNumericHelper.setElementSelection(this.domElement, start, end); |
| 2774 | |
| 2775 | return this; |
| 2776 | } |
| 2777 | |
| 2778 | /** |
| 2779 | * Select only the decimal part in the formatted element content, whatever the value of `selectNumberOnly` |
no test coverage detected