Skip to content

Commit bed2b7e

Browse files
author
Guillaume Tournier
committed
fix file allowBlank
ts: add emailDomain msg
1 parent 227dc79 commit bed2b7e

File tree

8 files changed

+12
-5
lines changed

8 files changed

+12
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ The default error messages are:
476476
477477
> Note: incorrect `minSize` or `maxSize` options will display an error in the console
478478
479+
> Note: for an optional file input, don't forget to pass `allowBlank: true`
480+
479481

480482
### validateForm
481483

examples/src/field-validation-form.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import PropTypes from 'prop-types'
22
import React, { Component } from 'react'
33
import { reduxForm, Field, FormSection } from 'redux-form'
4-
import { connect } from 'react-redux'
54
import { FormattedMessage } from 'react-intl'
65
import Validators, {
76
acceptance,

examples/src/general-validation-form.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import PropTypes from 'prop-types'
22
import React, { Component } from 'react'
33
import { reduxForm, Field, FormSection } from 'redux-form'
4-
import { connect } from 'react-redux'
54
import { FormattedMessage } from 'react-intl'
65
import {
76
acceptance,

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface ValidatorMessages {
3535
dateInvalid: ValidatorMessage
3636
dateRange: ValidatorMessage
3737
email: ValidatorMessage
38+
emailDomain: ValidatorMessage
3839
equalTo: ValidatorMessage
3940
even: ValidatorMessage
4041
exclusion: ValidatorMessage

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-form-validators",
3-
"version": "3.3.0",
3+
"version": "3.3.1",
44
"description": "Simple validations with redux-form / react-final-form",
55
"module": "lib/index.js",
66
"main": "lib/index.js",

src/__tests__/allow-blank.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Validator option: allowBlank', function () {
1919
assert.ok(test(length, blank, { is: 300, allowBlank: false }).indexOf('form.errors') === 0)
2020
assert.ok(test(numericality, blank, { allowBlank: false }).indexOf('form.errors') === 0)
2121
assert.ok(test(url, blank, { allowBlank: false }).indexOf('form.errors') === 0)
22+
assert.ok(test(file, blank, { allowBlank: false }).indexOf('form.errors') === 0)
2223
})
2324
assert.ok(test(file, new FileList(), { allowBlank: false }).indexOf('form.errors') === 0)
2425
})
@@ -32,6 +33,7 @@ describe('Validator option: allowBlank', function () {
3233
assert.ok(!test(length, blank, { is: 300, allowBlank: true }))
3334
assert.ok(!test(numericality, blank, { allowBlank: true }))
3435
assert.ok(!test(url, blank, { allowBlank: true }))
36+
assert.ok(!test(file, blank, { allowBlank: true }))
3537
})
3638
assert.ok(!test(file, new FileList(), { allowBlank: true }))
3739
})
@@ -49,6 +51,7 @@ describe('Validator option: allowBlank', function () {
4951
assert.ok(allowBlank !== (test(length, blank, { is: 300 }).indexOf('form.errors') === 0))
5052
assert.ok(allowBlank !== (test(numericality, blank).indexOf('form.errors') === 0))
5153
assert.ok(allowBlank !== (test(url, blank).indexOf('form.errors') === 0))
54+
assert.ok(allowBlank !== (test(file, blank).indexOf('form.errors') === 0))
5255
})
5356
})
5457

src/file.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ let file = memoize(function ({
4646
let isAFileList = isFileList(value)
4747

4848
// special blank check
49-
if ((allowBlank != null ? allowBlank : Validators.defaultOptions.allowBlank) && isAFileList && value.length === 0) {
49+
if (
50+
(allowBlank != null ? allowBlank : Validators.defaultOptions.allowBlank) &&
51+
(typeof value === 'string' ? value.trim() === '' : isAFileList && value.length === 0)
52+
) {
5053
return
5154
}
5255
if (!isAFileList) {

0 commit comments

Comments
 (0)