You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my large web app I have multiple forms with many different use cases for number inputs. When I want user to put a value in USD it should display nicely using expected formatting and enforce up to 2 decimal digits. Having "$" prefix is OK, but actually formatting and enforcing precision is a level-up in terms of UX.
functionformatForField(v: string){// add grouping separator if props.grouping === true// add decimal separator if props.precision > 0 or undefined// cut decimal part if props.precision > 0}functionformatForEmit(v: string){returnparseNumber(formatForField(v));}functionparseNumber(v: string){// remove everything except first occurrence of decimal separator and `-` sign before passing text to `parseFloat`}
We could take some inspiration from PrimeVue's InputNumber. However their API binds itself strongly to Intl.NumberFormat`. We could deliver better DX with:
grouping: Boolean (default: false)
precision: Number (default: 0) – to handle both min and max as I don't see the reason for split
formatterOptions: Intl.NumberFormatOptions – total flexibility without polluting component's API
Edit: I will not continue subject of grouping/formatting in this issue in order to keep it focused on precision and hopefully get it done faster.
J-Sek
changed the title
[Feature Request] Strict precision and grouping for VNumberInput
[Feature Request] Strict precision for VNumberInput
Jul 30, 2024
Problem to solve
In my large web app I have multiple forms with many different use cases for number inputs. When I want user to put a value in USD it should display nicely using expected formatting and enforce up to 2 decimal digits. Having "$" prefix is OK, but actually formatting and enforcing precision is a level-up in terms of UX.
Playground
Proposed solution
precision
blur
event should cut off unnecessary characters (it would be great to never emit them to the parent component)Simplified implementation:
I think implementation would require additional props for grouping character and decimal separator.
Related to:
vue-currency-input
supports onlyv-text-field
and I personally find it cumbersome and compromising on UX)maska
is a good fit... and again, I would need to recreate VNumberInput's controls)The text was updated successfully, but these errors were encountered: