MCPcopy
hub / github.com/autoNumeric/autoNumeric / setUnformatted

Method setUnformatted

src/AutoNumeric.js:2205–2230  ·  view source on GitHub ↗

* Set the given value directly as the DOM element value, without formatting it beforehand. * You can also set the value and update the setting in one go (the value will again not be formatted immediately). * * @param {number|string} value * @param {object} [options=null] * @

(value, options = null)

Source from the content-addressed store, hash-verified

2203 * @throws
2204 */
2205 setUnformatted(value, options = null) {
2206 //TODO Should we use `AutoNumeric.unformat()` here and set the unformatted result in case `value` is formatted?
2207 if (value === null || AutoNumericHelper.isUndefined(value)) {
2208 return this;
2209 }
2210
2211 // The options update is done only if the `value` is not null
2212 if (!AutoNumericHelper.isNull(options)) {
2213 this._setSettings(options, true); // We do not call `update` here since this would call `set` too
2214 }
2215
2216 const strippedValue = this.constructor._removeBrackets(value, this.settings);
2217 const normalizedValue = this.constructor._stripAllNonNumberCharacters(strippedValue, this.settings, true, this.isFocused);
2218 if (!AutoNumericHelper.isNumber(normalizedValue)) {
2219 AutoNumericHelper.throwError(`The value is not a valid one, it's not a numeric string nor a recognized currency.`);
2220 }
2221
2222 if (this.constructor._isWithinRangeWithOverrideOption(normalizedValue, this.settings)) {
2223 // If the `normalizedValue` is in the range
2224 this.setValue(value);
2225 } else {
2226 AutoNumericHelper.throwError(`The value is out of the range limits [${this.settings.minimumValue}, ${this.settings.maximumValue}].`);
2227 }
2228
2229 return this;
2230 }
2231
2232 /**
2233 * Set the given value directly as the DOM element value, without formatting it beforehand, and without checking its validity.

Callers 2

constructorMethod · 0.80

Calls 9

_setSettingsMethod · 0.95
setValueMethod · 0.95
isUndefinedMethod · 0.80
isNullMethod · 0.80
_removeBracketsMethod · 0.80
isNumberMethod · 0.80
throwErrorMethod · 0.80

Tested by

no test coverage detected