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

Input breaks when using watch options and autoDecimalDigits false #419

Open
acirinelli opened this issue Jul 29, 2024 · 3 comments
Open

Comments

@acirinelli
Copy link

acirinelli commented Jul 29, 2024

Vue Currency Input version

v3.0.3

Vue version

v3.2.45

What browser are you using?

Chrome

What operating system are you using?

MacOS

Reproduction link

https://codesandbox.io/s/muddy-frost-p7qgv2?file=/src/components/VCurrencyField.vue:1006-1023

Describe your issue

When using watch options and autoDecimalDigits:false, the input behaves in a strange way where it breaks after each number press and only accepts the last number. See code sandbox for working example.

It seems to only continue working correctly if precision is set to 0.

@acirinelli
Copy link
Author

@dm4t2 Possible solution:

setOptions function does not pass the hideNegligibleDecimalDigits to the format() function. It's always set to false.

setOptions(options) {
        this.init(options);
        this.format(this.currencyFormat.format(this.validateValueRange(this.numberValue)));
        this.onChange(this.getValue());
    }

We should pass in the option:

setOptions(options) {
        this.init(options);
        this.format(this.currencyFormat.format(this.validateValueRange(this.numberValue)), this.options.hideNegligibleDecimalDigitsOnFocus);
        this.onChange(this.getValue());
    }

@dm4t2
Copy link
Owner

dm4t2 commented Jul 31, 2024

Same issue as #400. You can avoid this by checking if the options have actually really changed before calling setOptions in options watcher or by using single props for each option (rather than an object for all options).

Maybe you also have an idea why the options watcher has such a weird behavior?

@acirinelli
Copy link
Author

acirinelli commented Aug 2, 2024

Same issue as #400. You can avoid this by checking if the options have actually really changed before calling setOptions in options watcher or by using single props for each option (rather than an object for all options).

Maybe you also have an idea why the options watcher has such a weird behavior?

As far as I can tell it's because of the way this function is defined and the second parameter is always false:
format(value: string | null, hideNegligibleDecimalDigits = false)

setOptions needs to pass it in, see comment above. I made that change in my fork and it works perfect.

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