Skip to content

Fix required number input does not require a value #538

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

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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