MCPcopy
hub / github.com/autoNumeric/autoNumeric / _onFormReset

Method _onFormReset

src/AutoNumeric.js:7785–7794  ·  view source on GitHub ↗

* Handler for 'reset' events caught on the parent element. * When such event is detected, then every child AutoNumeric elements must format their default value that the browser is forcing upon them. * * @private

()

Source from the content-addressed store, hash-verified

7783 * @private
7784 */
7785 _onFormReset() {
7786 const inputElements = this._getFormAutoNumericChildren(this.parentForm);
7787 const aNElements = inputElements.map(aNElement => this.constructor.getAutoNumericElement(aNElement));
7788 // Tell all the AutoNumeric children to format their default value
7789 aNElements.forEach(aNElement => {
7790 const val = this._getDefaultValue(aNElement.node());
7791 // aNElement.set(val); //XXX If I use that line, the format is first correctly done, but the form reset is still not finished and will overwrite the formatting. This is why we need to use the following setTimeout line.
7792 setTimeout(() => aNElement.set(val), 0); //XXX This is an ugly hack, but it seems to be the accepted answer to this problem (https://stackoverflow.com/a/8152960/2834898). This is sad. Do note that I use '0ms' here since using `setTimeout` will push that code on the event stack, and as soon as the reset will be finished, this will be run (see https://stackoverflow.com/a/23987283/2834898).
7793 });
7794 }
7795
7796 /**
7797 * Unformat the element value according to the `unformatOnSubmit` option

Callers 1

_setupFormListenerMethod · 0.95

Calls 5

_getDefaultValueMethod · 0.95
getAutoNumericElementMethod · 0.80
nodeMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected