From f95b38c5d6dae895283d95a0541acc8d06d9834f Mon Sep 17 00:00:00 2001 From: pacopage Date: Wed, 24 Oct 2018 22:50:49 +0200 Subject: [PATCH] Fix required number input does not require a value --- src/utils/validators.js | 4 ++-- test/unit/specs/utils/validators.spec.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/validators.js b/src/utils/validators.js index 05f6c7c6..26cfe5d8 100644 --- a/src/utils/validators.js +++ b/src/utils/validators.js @@ -1,4 +1,4 @@ -import { defaults, isNil, isNumber, isInteger, isString, isArray, isFunction } from "lodash"; +import { defaults, isNil, isNumber, isInteger, isString, isArray, isFunction, isFinite } from "lodash"; import fecha from "fecha"; let resources = { @@ -66,7 +66,7 @@ const validators = { if (res != null) return res; let err = []; - if (isNumber(value)) { + if (isFinite(value)) { if (!isNil(field.min) && value < field.min) { err.push(msg(messages.numberTooSmall, field.min)); } diff --git a/test/unit/specs/utils/validators.spec.js b/test/unit/specs/utils/validators.spec.js index 73a407ce..731d074c 100644 --- a/test/unit/specs/utils/validators.spec.js +++ b/test/unit/specs/utils/validators.spec.js @@ -31,6 +31,12 @@ describe("Validators", () => { check(v.number, null, field, 1); }); + it("should give error if value is NaN or Infinity", () => { + check(v.number, NaN, field, 1); + check(v.number, Infinity, field, 1); + check(v.number, -Infinity, field, 1); + }); + it("should give error if value is smaller than min", () => { check(v.number, -1, field, 1); check(v.number, 0, field, 1); @@ -68,7 +74,7 @@ describe("Validators", () => { // invalid integer check(v.integer, 3.14, field, 1); // invalid number, invalid integer - check(v.integer, "3.14", field, 2); + check(v.integer, NaN, field, 2); }); it("should not give error if value is integer", () => {