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

numericality greaterThan is always required #31

Closed
droganov opened this Issue Feb 12, 2015 · 8 comments

Comments

Projects
None yet
2 participants
@droganov

droganov commented Feb 12, 2015

Hello,
I my case price field is optional, but if it's filled, then it should be a positive integer.

How do I configure the schema?

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 12, 2015

Owner
var constraints = {
  price: {
    numericality: {
      onlyInteger: true,
      greaterThan: 0
    }
  }
};

validate({}, constraints);
// => undefined

validate({price: 0}, constraints);
// => {price: ["Price must be greater than 0"]}

validate({price: 1.2}, constraints);
// => {price: ["Price must be an integer"]}
Owner

ansman commented Feb 12, 2015

var constraints = {
  price: {
    numericality: {
      onlyInteger: true,
      greaterThan: 0
    }
  }
};

validate({}, constraints);
// => undefined

validate({price: 0}, constraints);
// => {price: ["Price must be greater than 0"]}

validate({price: 1.2}, constraints);
// => {price: ["Price must be an integer"]}
@droganov

This comment has been minimized.

Show comment
Hide comment
@droganov

droganov Feb 12, 2015

Nicklas, my config is:

price:
    numericality:
        greaterThan: 0
        onlyInteger: true
        notGreaterThan: "Положительное число"

I see 2 problems.

  1. I get must be greater than 0 exception for an empty field
  2. notGreaterThan option is replaced with default error message

When I enter positive integer, I see no error message.

Version is 0.4.0

droganov commented Feb 12, 2015

Nicklas, my config is:

price:
    numericality:
        greaterThan: 0
        onlyInteger: true
        notGreaterThan: "Положительное число"

I see 2 problems.

  1. I get must be greater than 0 exception for an empty field
  2. notGreaterThan option is replaced with default error message

When I enter positive integer, I see no error message.

Version is 0.4.0

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 12, 2015

Owner

You cannot set a greater than only message like that. The validators only accepts "message", the other ones are when setting default messages.

I don't really understand problem #1, the validator will accept all integers above 0 and reject all values that aren't empty.

On Thu, Feb 12, 2015 at 12:29 PM, droganov notifications@github.com
wrote:

Nicklas, my config is:

price:
  numericality:
      greaterThan: 0
      onlyInteger: true
      notGreaterThan: "Положительное число"

I see 2 problems.

  1. I get must be greater than 0 exception for an empty field
  2. notGreaterThan option is replaced with default error message
    When I enter positive integer, I see no error message.

Version is 0.4.0

Reply to this email directly or view it on GitHub:
#31 (comment)

Owner

ansman commented Feb 12, 2015

You cannot set a greater than only message like that. The validators only accepts "message", the other ones are when setting default messages.

I don't really understand problem #1, the validator will accept all integers above 0 and reject all values that aren't empty.

On Thu, Feb 12, 2015 at 12:29 PM, droganov notifications@github.com
wrote:

Nicklas, my config is:

price:
  numericality:
      greaterThan: 0
      onlyInteger: true
      notGreaterThan: "Положительное число"

I see 2 problems.

  1. I get must be greater than 0 exception for an empty field
  2. notGreaterThan option is replaced with default error message
    When I enter positive integer, I see no error message.

Version is 0.4.0

Reply to this email directly or view it on GitHub:
#31 (comment)

@droganov

This comment has been minimized.

Show comment
Hide comment
@droganov

droganov Feb 12, 2015

Ok, I can reconfigure messages, but as for validation, I expect validator to accept empty value, since the field is not required.

droganov commented Feb 12, 2015

Ok, I can reconfigure messages, but as for validation, I expect validator to accept empty value, since the field is not required.

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 12, 2015

Owner

But it does accept empty values as in my example? Or do you have an example of where it doesn't work?

Owner

ansman commented Feb 12, 2015

But it does accept empty values as in my example? Or do you have an example of where it doesn't work?

@droganov

This comment has been minimized.

Show comment
Hide comment
@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Feb 12, 2015

Owner

Ah, the problem is that it doesn't accept empty strings. I'll make a fix for this.

Owner

ansman commented Feb 12, 2015

Ah, the problem is that it doesn't accept empty strings. I'll make a fix for this.

@droganov

This comment has been minimized.

Show comment
Hide comment
@droganov

droganov Feb 12, 2015

Great, thank you!

droganov commented Feb 12, 2015

Great, thank you!

@ansman ansman closed this in c6e8fe3 Mar 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment