Modules: enhanced-redux-form/actions/enhancedFormActions

All functions in this module are action creators and the return value should be passed to the redux store dispatch() function

Source:

Methods


clearValidation(form [, fields])

Removes validation from the form on the specified fields

Parameters:
Name Type Argument Description
form string

The name of the form

fields Array.<string> <optional>

The fields to remove validation from. If not specified, removes from all fields (including any general form error)

Source:
Returns:

The action

Type
object

destroyEnhancedForm(name)

Note: this action is used internally by enhanced-redux-form. You will probably not need this for general usage

Called by enhancedReduxFormMiddleware whenever the destroy() action of redux-form is called. Will cause the attached enhanced state to be destroyed as well

Parameters:
Name Type Description
name string

The name of the form that is being unmounted

Source:
Returns:

The action

Type
object

extractFormValue(formValues, fieldName)

Extracts the given field from the given form values. If the field name is separated by dots, do a deep lookup in the form values.

Parameters:
Name Type Description
formValues object

Object containing all form values

fieldName string

Name of field to retrieve

Source:
Returns:

The value or undefined if it is not found


formShouldValidate(form, fields)

Note: this action is used internally by enhanced-redux-form. You will probably not need this for general usage

Called by the enhancedReduxFormMiddleware to indicate that certain fields of a form should be validated. This state is picked up by the decorated form to trigger validation.

Parameters:
Name Type Description
form string

The name of the form

fields Array.<string>

An array of fields that should be validated.

Source:
Returns:

The action

Type
object

handleSubmitErrors(form, errorObj [, transformApiFieldNames])

Note: this action is used internally by enhanced-redux-form. You will probably not need this for general usage

Handles submission errors that are thrown during form submission. On development, verifies that the fields on the given errors array exist on the form.

Parameters:
Name Type Argument Description
form string

The form that is being submitted

errorObj Object

An object containing an error response from the backend API

Properties
Name Type Argument Description
message string <optional>

A general error message

fields Array <optional>

An array of submission errors per field

fields[].field string

The name of the field that the error occurred on

fields[].message string

The error message for the field

transformApiFieldNames function <optional>

A function that maps the field names in the validation errors returned by the API to field names in the actual form.

Source:
Returns:

Function that will be handled by redux-thunk

Type
function

registerForm(form, validation [, wizardName])

Note: this action is used internally by enhanced-redux-form. You will probably not need this for general usage

Registers mounting of a form with validation. This registration is used by the enhancedReduxFormMiddleware to listen for events configured in the validation config object and trigger validation if neccessary

Parameters:
Name Type Argument Default Description
form string

The name of the form

validation Object.<string, ValidationConfig>

The validation configuration object. The keys of this object correspond to names of fields in the form, and the values are the corresponding validation.

wizardName string <optional>
null

The name of the enhancedFormWizard this form is part of

Source:
Returns:

Function that will be handled by redux-thunk

Type
function

submitForm(form, validation [, formProps], submitHandler [, transformApiFieldNames] [, submitSuccessHandler] [, submitFailHandler] [, generalErrorMessage], wizardRoutingAdapter, isWizardStep)

Validate the given form and call submitHandler when the validation succeeds

Parameters:
Name Type Argument Description
form

The name of the form to submit

validation

The validation configuration object as passed to the enhancedReduxForm HOC. See validateForm() for more info

formProps <optional>

The props that were passed to the form component that is being submitted. Will be passed on to the onSubmit handler.

submitHandler

The function to call when validation succeeds.

transformApiFieldNames function <optional>

A function that maps the field names in the validation errors returned by the API to field names in the actual form.

submitSuccessHandler function <optional>

A callback that will be called when the submitHandler function executes without error

submitFailHandler function <optional>

A callback that will be called when there is a validation error or an error in execution of submitHandler

generalErrorMessage string <optional>

When the API call comes back with an error that doesn't have the default error response shape, this message will be shown instead.

wizardRoutingAdapter
isWizardStep Boolean

If the current form is not a wizard step it should not go to the next step when a wizard has been found in store

Source:
Returns:

Function that will be handled by redux-thunk

Type
function

validateForm(validation, form [, fields])

Runs validation on the given form

Parameters:
Name Type Argument Description
validation Object.<string, ValidationConfig>

The validation configuration object. The keys of this object correspond to names of fields in the form, and the values are the corresponding validation.

form string

The name of the form to validate

fields Array.<string> <optional>

An array of field names to validate. If omitted, runs validation on all fields

Source:
Returns:

Function that will be handled by redux-thunk

Type
function

Type Definitions


ValidationConfig

Properties:
Name Type Argument Default Description
validateOn string | Array.<string> <optional>

A string or array of strings that specifies on which event the validation should trigger. See ValidateOn.js for possible values.

validators Array.<ValidationRule>

An array of validation rules to test this field for.

onlyValidateIfMounted boolean <optional>
true

If false, will also validate this field if it's not mounted in the form. An error in this validation will also block the form submission

Source:

ValidationRule

Properties:
Name Type Description
rule function

A function that returns true or false for valid or invalid. May also return a promise that resolves with true or false. It will receive the following arguments:

  • value The current value of the field
  • values An object containing all the values in the form
  • name The name of the field that is being validated
  • dispatch The redux store dispatch() method
message string

A message that should be set as error message when this field is invalid.

Source: