AutoNumeric v4.10.8: Value Set with set() Fails After form.reset()
Description
When using AutoNumeric v4.10.8, calling instance.set(value) immediately after a native form.reset() results in the value not being applied or persisting in the input.
Steps to Reproduce
-
Initialize an AutoNumeric instance on an input element within a form:
const autoNumericInstance = new AutoNumeric('#input', {
decimalPlaces: 2
});
-
Reset the form using the native form.reset() method:
document.getElementById('form').reset();
-
Immediately set a value using autoNumericInstance.set():
autoNumericInstance.set(1234.56);
-
Observe that the value is not applied to the input or is cleared.
Expected Behavior
The value set with autoNumericInstance.set(1234.56) should be applied and displayed correctly in the input, formatted according to the AutoNumeric configuration (e.g., 1,234.56).
Actual Behavior
The value is not applied, or the input remains empty (or reverts to its initial value as defined in the HTML).
Workarounds Attempted
-
Using wipe() and reinitializing:
document.getElementById('form').reset();
autoNumericInstance.wipe();
autoNumericInstance = new AutoNumeric('#input', {
decimalPlaces: 2
});
autoNumericInstance.set(1234.56);
This does not work, as the value is still not applied.
-
Using setTimeout with 0ms delay:
document.getElementById('form').reset();
setTimeout(() => {
autoNumericInstance.set(1234.56);
}, 0);
This reliably works, and the value is applied correctly.
Environment
- AutoNumeric Version: 4.10.8
- Environment: Web application, input inside a form
Additional Context
- The input is a standard
<input type="text"> with AutoNumeric applied.
- No other plugins or event listeners are known to interfere with the input.
- The issue persists even when reinitializing AutoNumeric after
form.reset().
- The issue no occurs on others non-autonumeric fields.
Example Code
// HTML
<form id="form">
<input type="text" id="input">
</form>
// JavaScript
const autoNumericInstance = new AutoNumeric('#input', {
decimalPlaces: 2
});
// This fails
document.getElementById('form').reset();
autoNumericInstance.set(1234.56); // Value not applied
// This works
document.getElementById('form').reset();
setTimeout(() => {
autoNumericInstance.set(1234.56); // Value applied correctly
}, 0);
Related Issues
- No exact match found in the AutoNumeric GitHub issues, but related discussions about
set() and reset event handling exist.
Please let me know if additional details or test cases are needed to investigate further.
AutoNumeric v4.10.8: Value Set with
set()Fails Afterform.reset()Description
When using AutoNumeric v4.10.8, calling
instance.set(value)immediately after a nativeform.reset()results in the value not being applied or persisting in the input.Steps to Reproduce
Initialize an AutoNumeric instance on an input element within a form:
Reset the form using the native
form.reset()method:Immediately set a value using
autoNumericInstance.set():Observe that the value is not applied to the input or is cleared.
Expected Behavior
The value set with
autoNumericInstance.set(1234.56)should be applied and displayed correctly in the input, formatted according to the AutoNumeric configuration (e.g.,1,234.56).Actual Behavior
The value is not applied, or the input remains empty (or reverts to its initial value as defined in the HTML).
Workarounds Attempted
Using
wipe()and reinitializing:This does not work, as the value is still not applied.
Using
setTimeoutwith 0ms delay:This reliably works, and the value is applied correctly.
Environment
Additional Context
<input type="text">with AutoNumeric applied.form.reset().Example Code
Related Issues
set()and reset event handling exist.Please let me know if additional details or test cases are needed to investigate further.