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

E_VALIDATION rule integer Value should be an integer #4215

Closed
simonecogno opened this issue Oct 17, 2017 · 4 comments
Closed

E_VALIDATION rule integer Value should be an integer #4215

simonecogno opened this issue Oct 17, 2017 · 4 comments

Comments

@simonecogno
Copy link

simonecogno commented Oct 17, 2017

Sails version: 0.12
Node version: 6.11.4
NPM version: 3.10.0
DB adapter name: sails-mongo
DB adapter version: 0.12
Operating system: Linux


I have a problem with integer types. If I set it to integer then if the value is null I receive the following error:
{"error":"E_VALIDATION","status":400,"summary":"1 attribute is invalid","model":"Test","invalidAttributes":{"test":[{"rule":"integer","message":"Value should be an integer"}]}}

My model configuration:

test: {
      type: 'integer'
 }

As I didn't set the require validator null values should be accepted.

If I set the value with a integer or witha a string containing an integer then it work fine.

What I'm doing wrong here? Or how can I allow null values on integer fields?

Link to stackoveflow question: https://stackoverflow.com/questions/46785754/sailsjs-e-validation-rule-integer-value-should-be-an-integer

@sailsbot
Copy link

Hi @simonecogno! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Verify "I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction."
  • Verify "I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(http://sailsjs.com), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails)."
  • Verify "I have already searched for related issues, and found none open (if you found a related closed issue, please link to it in your post)."
  • Verify "My issue title is concise, on-topic and polite ("jst.js being removed from layout.ejs on lift" is good; "templates dont work" or "why is sails dumb" are not so good)."
  • Verify "I have tried all the following (if relevant) and my issue remains:"
  • Verify "I can provide steps to reproduce this issue that others can follow."

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

@simonecogno
Copy link
Author

ok, fixed!

@sailsbot
Copy link

@simonecogno Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

@simonecogno
Copy link
Author

Ok fixed. The problem was that before the validation the value was NaN. Maybe this value was coming from the fronted input field or after the integer validation. Anyways it works fine by adding this check in the validation:

if (isNaN(attrs.test))
    attrs.test = null;

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

No branches or pull requests

2 participants