Skip to content

AutoNumeric value set with set() fails after form.reset() #810

Description

@alan-schwertner

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

  1. Initialize an AutoNumeric instance on an input element within a form:

    const autoNumericInstance = new AutoNumeric('#input', {
        decimalPlaces: 2
    });
  2. Reset the form using the native form.reset() method:

    document.getElementById('form').reset();
  3. Immediately set a value using autoNumericInstance.set():

    autoNumericInstance.set(1234.56);
  4. 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

  1. 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.

  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions