MCPcopy
hub / github.com/autoNumeric/autoNumeric / selectNumber

Method selectNumber

src/AutoNumeric.js:2682–2724  ·  view source on GitHub ↗

* Select only the numbers in the formatted element content, leaving out the currency symbol, whatever the value of the `selectNumberOnly` option * * @returns {AutoNumeric}

()

Source from the content-addressed store, hash-verified

2680 * @returns {AutoNumeric}
2681 */
2682 selectNumber() {
2683 //TODO Make sure the selection is ok when showPositiveSign is set to `true` (select the negative sign, but not the positive one)
2684 const unformattedValue = AutoNumericHelper.getElementValue(this.domElement);
2685 const valueLen = unformattedValue.length;
2686 const currencySymbolSize = this.settings.currencySymbol.length;
2687 const currencySymbolPlacement = this.settings.currencySymbolPlacement;
2688 const negLen = (!AutoNumericHelper.isNegative(unformattedValue, this.settings.negativeSignCharacter))?0:1;
2689 const suffixTextLen = this.settings.suffixText.length;
2690
2691 let start;
2692 if (currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.suffix) {
2693 start = 0;
2694 } else if (this.settings.negativePositiveSignPlacement === AutoNumeric.options.negativePositiveSignPlacement.left &&
2695 negLen === 1 && currencySymbolSize > 0) {
2696 start = currencySymbolSize + 1;
2697 } else {
2698 start = currencySymbolSize;
2699 }
2700
2701 let end;
2702 if (currencySymbolPlacement === AutoNumeric.options.currencySymbolPlacement.prefix) {
2703 end = valueLen - suffixTextLen;
2704 } else {
2705 switch (this.settings.negativePositiveSignPlacement) {
2706 case AutoNumeric.options.negativePositiveSignPlacement.left:
2707 end = valueLen - (suffixTextLen + currencySymbolSize);
2708 break;
2709 case AutoNumeric.options.negativePositiveSignPlacement.right:
2710 if (currencySymbolSize > 0) {
2711 end = valueLen - (currencySymbolSize + negLen + suffixTextLen);
2712 } else {
2713 end = valueLen - (currencySymbolSize + suffixTextLen);
2714 }
2715 break;
2716 default :
2717 end = valueLen - (currencySymbolSize + suffixTextLen);
2718 }
2719 }
2720
2721 AutoNumericHelper.setElementSelection(this.domElement, start, end);
2722
2723 return this;
2724 }
2725
2726 /**
2727 * Select only the integer part in the formatted element content, whatever the value of `selectNumberOnly`

Callers 3

selectMethod · 0.95

Calls 3

getElementValueMethod · 0.80
isNegativeMethod · 0.80
setElementSelectionMethod · 0.80

Tested by

no test coverage detected