Skip to content

Commit df43b58

Browse files
committed
fix: still call validators on whitespace
1 parent 4ad92d6 commit df43b58

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ If you provide this, it will be called with the output of `normalizeNumber`.
5252

5353
#### `validate?: Validator | Array<Validator>`
5454

55-
Unlike a normal `Field`, `NumericField` will call your validators with the normalized number from
55+
Unlike a normal `Field`, `NumericField` will call your validators with the normalized value from
5656
`normalizeNumber`. If its value is an invalid number but not whitespace, it will produce a
5757
"must be a number" validation error without calling your own validators.

src/createNumericField.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ function createNumericField<P: {
3636
validate = (value: any, allValues: Object, props: Object): ?string => {
3737
const normalizeNumber = this.props.normalizeNumber || defaultNormalize
3838
const normalized = normalizeNumber(value)
39-
if (typeof normalized === 'string') {
40-
if (WHITESPACE.test(normalized)) return
39+
if (typeof normalized === 'string' && !WHITESPACE.test(normalized)) {
4140
return 'must be a number'
4241
}
4342
const {validate} = this.props

0 commit comments

Comments
 (0)