validates numericality not working? #425

Closed
rassom opened this Issue Nov 2, 2012 · 9 comments

Projects

None yet

2 participants

@rassom
rassom commented Nov 2, 2012

I'm playing with validates numericality in my models instead of using regex, but putting it in my model doesn't create a ClientSideValidations error (desired behaviour) when I type in some letters on the front end. Whereas with my custom regex, that I used before numericality, did create an error.

What I am trying now:
validates :commission_minimum, :numericality => { :greater_than_or_equal_to => 0 }, :allow_blank => true

Before:
PRICE_REGEX = /^([1-9]\d{0,20}|0)(.\d{0,4})?$/
PRICE_ERROR_MESSAGE = "Must be a number. If you want to include decimals, please use comma as decimal separator. Periods (.) = thousand separator cannot be used."

validates :commission_minimum, :format => {:with => PRICE_REGEX, :message => PRICE_ERROR_MESSAGE }, :allow_blank => true

Does ClientSideValidations not work with the numericality greater_than_or_equal to or am I missing something?

@bcardarella
Contributor

@rassom this is strange, is the validator turned off? Because the validations should definitely be working:

https://github.com/bcardarella/client_side_validations/blob/3-2-stable/coffeescript/rails.validations.coffee#L225 will actually check to see if the value is a number

https://github.com/bcardarella/client_side_validations/blob/3-2-stable/coffeescript/rails.validations.coffee#L430 is the regex to check to see if the value is a number or not

Can I get the full HTML from the page?

@rassom
rassom commented Nov 2, 2012

@bcardarella Thanks :) Where could it be turned off?

Do you still have my repo on your machine?
If yes, just change the validates :commission_minimum field in models/broker.rb to

validates :commission_minimum, :numericality => { :greater_than_or_equal_to => 0 }, :allow_blank => true

Then log in to the dev site and choose Broker in the top menu, and try entering something in the Commission Minimum field on the front end.

@bcardarella
Contributor

I deleted the repo when I finished. If you can share the full HTML output that should suffice.

@rassom
rassom commented Nov 2, 2012

Sure, please see attached.

Thanks :-)

On Fri, Nov 2, 2012 at 11:24 PM, Brian Cardarella
notifications@github.comwrote:

I deleted the repo when I finished. If you can share the full HTML output
that should suffice.


Reply to this email directly or view it on GitHubhttps://github.com/bcardarella/client_side_validations/issues/425#issuecomment-10032225.

@bcardarella bcardarella added a commit that closed this issue Nov 7, 2012
@bcardarella bcardarella Fix #425 4f6bdde
@bcardarella bcardarella added a commit that referenced this issue Nov 7, 2012
@bcardarella bcardarella Fix #425 94375eb
@bcardarella
Contributor

@rassom sorry it took a few days to address, this was a legit bug. Point your app at the master branch and it should be OK. I'll do a patch release sometime next week after I get through some of these other open issues.

@rassom
rassom commented Nov 7, 2012

@bcardarella Beautiful! Thanks once again for your help. Much appreciated! :-)

@rassom
rassom commented Dec 16, 2012

@bcardarella I just tested and it still doesn't work in client_side_validations 3.2.1 ?

@bcardarella
Contributor

@rassom the new version has not been released yet so you'll need to pull from the 3-2-stable branch on Github if you want the fix. I have been pretty slammed and haven't had the time to close out a few other issues before releasing the next patch

@rassom
rassom commented Dec 16, 2012

Ahh, okay :) Thought I should just pull latest (3.2.1) to get the fix. My bad - sorry.

@tagliala tagliala added a commit that referenced this issue Nov 10, 2016
@tagliala tagliala fixup! Fix #425 9178844
@tagliala tagliala added a commit that referenced this issue Nov 10, 2016
@tagliala tagliala Merge branch 'fix-numericality'
* fix-numericality:
  Fix JavaScript numericality validator
  fixup! Fix #425
ae38c15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment