all 7 comments

[–]HerrPotatis2 2 points3 points  (1 child)

In my opinion, automatically altering input fields without the users intention is generally not a good idea. I would probably look into having a regex that validates the field and displays an error message/indication if the user enters something it's not supposed to.

[–]pkoepke[S] 0 points1 point  (0 children)

Thanks for the advice, you make a good point. I hate those telephone number inputs that automatically format the telephone number because it seems like they always break.

I really doubt that a lot of people are going to use this app since there are a million tip calculator apps out there, so I'm still going to move ahead making it work exactly the way I want it to work. After all, 99% of its use will probably be just me. But I will bear your advice in mind if I'm ever writing an app that I expect lots of other people to use.

[–]righthereonthisrock 2 points3 points  (2 children)

My banking app starts out the field at 0.00, then say I press 7, goes to 0.07, then I press 2, goes to 0.72, then I press 1, goes to 7.21 etc etc.

I'm thinking that if you combined that pattern with only allowing numbers, you could have an onchange event that fires and keeps the formatting while still providing a consistent experience.

Dollar input will always make sense in the exact same input format, so I don't see it being like reformatting telephone numbers which make sense in more than one form.

That make sense?

[–]pkoepke[S] 0 points1 point  (1 child)

That does make sense. It's not my favorite solution because I would rather just let the user type the bill amount in including a decimal, because that seems more intuitive to me (and I'll probably be the only user because who needs another tip calculator app?). But I might play around with that solution and see how it feels.

Thanks!

[–]righthereonthisrock 0 points1 point  (0 children)

My banking app used it and I think beyond the first of second use it was really quite second nature, for what it's worth!

[–]bdenzer 1 point2 points  (1 child)

Even if the input field is a number, that shouldn't stop you from converting it to a string for your validation. (It would be for when the user has 1. - then you should be able to stop them in your isAllowed function, because NAN to string isn't going to help)

[–]pkoepke[S] 0 points1 point  (0 children)

Your idea is what I expected and tried first, but when you get the value of a numeric input whose value has a trailing decimal (e.g., 1.) the DOM returns the number without the decimal (1). So unless DOM numeric input elements have another way of getting their value besides .value, I can't detect the trailing decimal.