Skip to content

Commit

Permalink
fix immutable support in lose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
esetnik committed May 28, 2019
1 parent 61d8de2 commit 541ec8f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/handleSubmit.js
Expand Up @@ -3,6 +3,7 @@ import isPromise from 'is-promise'
import type { SubmitFunction } from './types'
import type { Props } from './createReduxForm'
import SubmissionError from './SubmissionError'
import { List } from 'immutable'

const isSubmissionError = error => error && error.name === SubmissionError.name

Expand All @@ -11,9 +12,14 @@ const mergeErrors = ({ asyncErrors, syncErrors }) =>
? asyncErrors.merge(syncErrors).toJS()
: { ...asyncErrors, ...syncErrors }

// fields may be an Immutable List which cannot be spread
// convert the fields to an array if necessary
const makeFieldsArray = (fields: string[] | List<string>) =>
List.isList(fields) ? ((fields: any): List<string>).toArray() : fields

const executeSubmit = (
submit: SubmitFunction,
fields: string[],
fields: string[] | List<string>,
props: Props
) => {
const {
Expand All @@ -28,6 +34,8 @@ const executeSubmit = (
values
} = props

fields = makeFieldsArray(fields)

let result
try {
result = submit(values, dispatch, props)
Expand Down Expand Up @@ -96,7 +104,7 @@ const handleSubmit = (
props: Props,
valid: boolean,
asyncValidate: Function,
fields: string[]
fields: string[] | List<string>
) => {
const {
dispatch,
Expand All @@ -108,7 +116,9 @@ const handleSubmit = (
persistentSubmitErrors
} = props

touch(...Array.from(fields)) // mark all fields as touched
fields = makeFieldsArray(fields)

touch(...fields) // mark all fields as touched

if (valid || persistentSubmitErrors) {
const asyncValidateResult = asyncValidate && asyncValidate()
Expand Down

0 comments on commit 541ec8f

Please sign in to comment.