* Set the given value on the DOM element, without affecting the `rawValue`. * This sends an 'autoNumeric:formatted' event if the new value is different from the old one. * * @param {number|string} newElementValue * @param {boolean} [sendFormattedEvent=true] If set to `true`, then
(newElementValue, sendFormattedEvent = true)
| 2292 | * @private |
| 2293 | */ |
| 2294 | _setElementValue(newElementValue, sendFormattedEvent = true) { |
| 2295 | //TODO Use an internal attribute to track the current value of the element `formattedValue` (like its counterpart `rawValue`). This would allow us to avoid calling `getElementValue` many times |
| 2296 | const oldElementValue = AutoNumericHelper.getElementValue(this.domElement); |
| 2297 | |
| 2298 | // Only update the value if it's different from the current one |
| 2299 | if (newElementValue !== oldElementValue) { |
| 2300 | this.internalModification = true; |
| 2301 | AutoNumericHelper.setElementValue(this.domElement, newElementValue); |
| 2302 | this.internalModification = false; |
| 2303 | |
| 2304 | if (sendFormattedEvent) { |
| 2305 | this._triggerEvent(AutoNumeric.events.formatted, this.domElement, { |
| 2306 | oldValue : oldElementValue, |
| 2307 | newValue : newElementValue, |
| 2308 | oldRawValue: this.rawValue, |
| 2309 | newRawValue: this.rawValue, |
| 2310 | isPristine : this.isPristine(false), |
| 2311 | error : null, |
| 2312 | aNElement : this, |
| 2313 | }); |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | return this; |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Set the given value on the DOM element, and the raw value on `this.rawValue`, if both are given. |
no test coverage detected