Skip to content

Cannot use a higher-order function in Field Validation #3288

@duro

Description

@duro

Are you submitting a bug report or a feature request?

Bug

What is the current behavior?

When using field level validators, I am unable to use a higher order function to produce the validation function

This works:

const required = value => (value ? undefined : 'Required')

<Field
  label="Email"
  name="email"
  component={InputField}
  validate={required}
  placeholder="email"
  type="text"
/>

This DOES NOT work:

const required = (msg = 'Default Message') => value => (value ? undefined : msg)

<Field
  label="Email"
  name="email"
  component={InputField}
  validate={required('Message Override')}
  placeholder="email"
  type="text"
/>

What is the expected behavior?

I would expect to pass into the field validator a returned function that matches the validator interface even if it was produced by a higher order function

Sandbox Link

https://codesandbox.io/s/G6ARklAMr

What's your environment?

Redux Form: 7.0.3
OS: macOS
Browser: Chrome 60

Other information

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions