Skip to content

Commit

Permalink
Fix required number input does not require a value
Browse files Browse the repository at this point in the history
  • Loading branch information
pacopage committed Oct 24, 2018
1 parent d69e0af commit f95b38c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/utils/validators.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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));
}
Expand Down
8 changes: 7 additions & 1 deletion test/unit/specs/utils/validators.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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", () => {
Expand Down

0 comments on commit f95b38c

Please sign in to comment.