* 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
()
| 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 |
no test coverage detected