Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to catch the error or set an errorhandler for the errors thrown by autonumeric. #706

Open
anandphulwani opened this issue Jan 8, 2021 · 1 comment

Comments

@anandphulwani
Copy link

Goal To Achieve

  1. Catch the error thrown by autonumeric and display it in a better way on the page in an error block/div.
  2. Generate an error on a wrong key as well like inputting a alphabet(a,b,c) in the field.

Current behavior

Error is being displayed on the console.

Expected behavior

Error should be catched, and the catch message should be displayed.

Steps to reproduce the problem

  1. Use autoNumeric version <v4.6.0>
  2. In the browser Firefox version <84.0>
  3. On the Windows 10 operating system
  4. Then instantiate the autoNumeric object with the following options:
        try {
            new AutoNumeric(element[0],{
                maximumValue: 5000,
                unformatOnSubmit: true,
                showWarnings: true
            });
        } catch (e) {
            console.log("I have catched this error.");
        }
  1. The error is displayed on console, rather than the message.

I debug the process and found out that the error is thrown by static throwError(message) function in AutoNumericHelper.js , but i am unable to catch it, is there a way to catch it or is there a way to override the throwError function or should i just rewrite the throwError function in the AutoNumericHelper.js.

Also is there a way to capture alphabets/symbols pressed in the input control, as far as i understand the flow, the onKeyDown is the first event handler to be called and should be the function which checks for invalid keys, any help in this will be useful.

Thanks

@AlexandreBonneau
Copy link
Member

Hello @anandphulwani , sorry for the late reply.
You could try using the AutoNumeric custom events, for instance 'autoNumeric:invalidValue'.
Some of those events have a useful payload you might want to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants