GithubHelp home page GithubHelp logo

Comments (9)

indrimuska avatar indrimuska commented on May 18, 2024

Ok, got it, the problem is here:
https://github.com/bvaughn/angular-form-for/blob/master/source/services/model-validator.ts#L421

@bvaughn is there any reason to check if minimum is set/not-null/not-zero?
Could we simply check if it is just a valid number !isNaN(validationRules.minimum) ?

from angular-form-for.

bvaughn avatar bvaughn commented on May 18, 2024

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.

from angular-form-for.

indrimuska avatar indrimuska commented on May 18, 2024

Yes, sure, I know a field could be optional and, at the same time, have a minimum constraint.
Isn't it enough to check if validationRules.minimum || validationRules.minimum === 0?

from angular-form-for.

bvaughn avatar bvaughn commented on May 18, 2024

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 undefined, null, or ''.)

Or yeah, I guess we could also just explicitly check for 0 like you suggest :)

from angular-form-for.

indrimuska avatar indrimuska commented on May 18, 2024

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:

Input Output
0 "valid"
1 "valid"
function () { } "valid"
{ rule: 0 } "valid"
null "invalid"
undefined "invalid"
true "invalid"
false "invalid"
" " "invalid"

What are your thought?

from angular-form-for.

bvaughn avatar bvaughn commented on May 18, 2024

Just checking if it's not falsy or 0 (a number) would be sufficient though
because functions and objects are both truthy things in JavaScript :)

On Saturday, December 12, 2015, indrimuska [email protected] wrote:

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:
Input Output 0 "valid" 1 "valid" function () { } "valid" { rule: 0 }
"valid" null "invalid" undefined "invalid" true "invalid" false "invalid" "
" "invalid"

What are your thought?


Reply to this email directly or view it on GitHub
#179 (comment)
.

from angular-form-for.

indrimuska avatar indrimuska commented on May 18, 2024

Ok, but, as you said, this will accept inputs like " " or true and convert them to integer 1. This means that if you set minimum rule to true and your field is equal to 0 it will cause a validation error.
Anyway, I know that setting minimum rule to true is not a correct behavior, so if you like we can just use the same simplest rule I already described before.

from angular-form-for.

bvaughn avatar bvaughn commented on May 18, 2024

Hmm. I'm all for robust checking of user input but it seems unlikely to
me that someone would configure their validation rules that way. I don't
feel strongly about this though- either approach would be fine,

On Saturday, December 12, 2015, indrimuska [email protected] wrote:

Ok, but, as you said, this will accept inputs like " " or true and
convert them to integer 1. This means that if you set minimum validation
to true and your field is equal to 0 it will cause a validation error.
Anyway, I know that setting minimum rule to true is not a correct
behavior, so if you like we can just use the same simplest rule I already
described before
#179 (comment)
.


Reply to this email directly or view it on GitHub
#179 (comment)
.

from angular-form-for.

indrimuska avatar indrimuska commented on May 18, 2024

Ok, I will create a PR with the simplest one. :)

from angular-form-for.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.