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

How do I initialise this textField with a pre-populated value? #11

Closed
PlasmaSoftUK opened this issue Sep 26, 2020 · 4 comments
Closed
Labels
good first issue Good for newcomers

Comments

@PlasmaSoftUK
Copy link

Looking at the demo app in CurrencyTextFieldDemoView if I change the value from 0.0 to 4.5

@State private var value: Double? = 4.5

I would expect the app to launch with a value of £4.50 in the text filed however, when run, the field still only shows the Placeholder of 'Amount'. If I type nothing but click the "Print" button with it still showing the Placeholder it then prints the value it was init'd with:

Optional(4.5)

So the value is there, its just not being displayed.

The other behaviour I think is odd, is that if I set the field to say 2.1 when I dismiss the keyboard I would expect that to re-format as £2.10 however its still displays as £2.1 which is obviously an improper currency format.

Thanks
Plasma

youjinp added a commit that referenced this issue Sep 26, 2020
@youjinp youjinp added the good first issue Good for newcomers label Sep 26, 2020
@youjinp
Copy link
Owner

youjinp commented Sep 26, 2020

Fixed them both. Thanks!

youjinp added a commit that referenced this issue Sep 26, 2020
@PlasmaSoftUK
Copy link
Author

Excellent, thank you for the quick fix.

The only other question I have is that I would like for it to always display in the $0.00 format, however if the value is a whole number it drops the decimal points. Is there an option to force it to always display in the same format. I'm looking at a list of values and it makes them look odd if some are $0 format and others are $0.00 format.

in the mean time I have changed the currencyFormat extension to this which forces it to always be $0.00 format:

        let formatter = Formatter.currency
        formatter.maximumFractionDigits = 2
        return formatter.string(from: NSNumber(value: self)) 

@youjinp
Copy link
Owner

youjinp commented Sep 28, 2020

Checkout the latest release, have added an option alwaysShowFractions. Also included an example in the demo!

@PlasmaSoftUK
Copy link
Author

Nice thanks for the quick turn around again! 👍

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

No branches or pull requests

2 participants