MCPcopy
hub / github.com/autoNumeric/autoNumeric / _setRawValue

Method _setRawValue

src/AutoNumeric.js:2253–2283  ·  view source on GitHub ↗

* Save the raw value inside the AutoNumeric object. * * @param {number|string|null} rawValue The numeric value as understood by Javascript like a `Number` * @param {boolean} [saveChangeToHistory=true] If set to `true`, then the change is recorded in the history array, otherwise it is

(rawValue, saveChangeToHistory = true)

Source from the content-addressed store, hash-verified

2251 * @private
2252 */
2253 _setRawValue(rawValue, saveChangeToHistory = true) {
2254 // Only set the raw value if the given value is different from the current one
2255 if (this.rawValue !== rawValue) { //TODO Manage the case where one value is a string while the other is a number?
2256 const oldRawValue = this.rawValue;
2257 // Update the raw value
2258 this.rawValue = rawValue; // By default, if the `rawValue` is changed programmatically
2259
2260 if ((!AutoNumericHelper.isNull(this.settings.rawValueDivisor) && this.settings.rawValueDivisor !== 0) && // Only divide if the `rawValueDivisor` option is set
2261 rawValue !== '' && rawValue !== null && // Do not modify the `rawValue` if it's an empty string or null
2262 this._isUserManuallyEditingTheValue()) { // If the user is manually changing the element value
2263 this.rawValue /= this.settings.rawValueDivisor;
2264 }
2265
2266 // Broadcast the `rawValueModified` event since the `rawValue` has been modified
2267 this._triggerEvent(AutoNumeric.events.rawValueModified, this.domElement, {
2268 oldRawValue,
2269 newRawValue: this.rawValue,
2270 isPristine : this.isPristine(true),
2271 error : null,
2272 aNElement : this,
2273 });
2274
2275 // Change the element style or use the relevant callbacks
2276 this._parseStyleRules();
2277
2278 if (saveChangeToHistory) {
2279 // Save in the history the last known raw value and formatted result selection
2280 window.requestAnimationFrame(() => this._historyTableAdd()); // The use of `requestAnimationFrame` fixes PR #731 by avoiding "Forced reflow"
2281 }
2282 }
2283 }
2284
2285 /**
2286 * Set the given value on the DOM element, without affecting the `rawValue`.

Callers 6

_onKeyupMethod · 0.95
_setValuePartsMethod · 0.95

Calls 6

_triggerEventMethod · 0.95
isPristineMethod · 0.95
_parseStyleRulesMethod · 0.95
_historyTableAddMethod · 0.95
isNullMethod · 0.80

Tested by

no test coverage detected