Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
Ok, I will create a PR with the simplest one. :)
from angular-form-for.
Related Issues (20)
- Can i validate HTML or other controls using Form-for HOT 21
- Form is submitted when required checkboxes are not checked HOT 8
- Feature request: never validate not-required blank/empty/unchecked inputs HOT 4
- text-field should support input filters HOT 9
- No option to add multiple custom rules to the same field HOT 4
- Checkbox Fix Release HOT 1
- Problem with latest release HOT 9
- Formatting - Select-field HOT 2
- Enable number fields HOT 6
- checkboxField change event does not fire HOT 1
- increment validation HOT 4
- SelectField auto selects the last option initially HOT 6
- Plans for Angular 2? HOT 2
- Support for asynchronous schemas HOT 2
- JSON Schema support HOT 1
- Add support for latest angular-material version HOT 3
- TypeError: Cannot read property 'unwatchers' of undefined HOT 4
- The homepage is dead HOT 1
- Dynamically change validationRules depending on submit action
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-form-for.