-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Minimum/maximum rule doesn't work when number is zero #179
Comments
Ok, got it, the problem is here: @bvaughn is there any reason to check if |
Ah. The general problem is that we shouldn't show a min/max validation error if the user didn't supply a value. That's more in the realm of required validation. (A field may have min/max constraints while at the same time being optional.) The problem is that 0 is a falsy value in JavaScript so we need to be careful about deciding when the user has supplied a value. That's why I'm checking to make sure there's a non-empty string (eg. '123') and that it's a legit number (eg '123' vs 'abc') and only then validating. |
Yes, sure, I know a field could be optional and, at the same time, have a minimum constraint. |
Oh! Haha! I was completely misunderstanding your question. I thought you were saying that it didn't work when the user supplied value was 0. You're saying it doesn't work when the minimum value is 0! Looks like we maybe need to do a similar, more robust form of checking for the min/max validation rules as we're doing for their values. (Not just rely on falsy checks, but more strictly check for Or yeah, I guess we could also just explicitly check for 0 like you suggest :) |
Aha, don't worry. Well, we must remember that minimum rule could be a number, an object or a function. So, don't re-invent the wheel, let's use angular utilities: function checkValue(value) {
if (angular.isObject(value) || angular.isFunction(value) || angular.isNumber(value))
console.log('valid');
else
console.log('invalid');
} I made some tests with this fn, and these are the results:
What are your thought? |
Just checking if it's not falsy or 0 (a number) would be sufficient though On Saturday, December 12, 2015, indrimuska notifications@github.com wrote:
|
Ok, but, as you said, this will accept inputs like |
Hmm. I'm all for robust checking of user input but it seems unlikely to On Saturday, December 12, 2015, indrimuska notifications@github.com wrote:
|
Ok, I will create a PR with the simplest one. :) |
Plunker example:
http://plnkr.co/edit/NfhwLeXPzmo9SANJuOrQ?p=preview
Looking for a fix.
EDIT: possible workaround is using a function rule as below:
The text was updated successfully, but these errors were encountered: