All functions in this module are action creators and the return value should be passed to the redux store dispatch() function
Methods
-
clearValidation(form [, fields])
-
Removes validation from the form on the specified fields
Parameters:
Name Type Argument Description formstring The name of the form
fieldsArray.<string> <optional>
The fields to remove validation from. If not specified, removes from all fields (including any general form error)
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 namestring The name of the form that is being unmounted
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 formValuesobject Object containing all form values
fieldNamestring Name of field to retrieve
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 formstring The name of the form
fieldsArray.<string> An array of fields that should be validated.
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 formstring The form that is being submitted
errorObjObject An object containing an error response from the backend API
Properties
Name Type Argument Description messagestring <optional>
A general error message
fieldsArray <optional>
An array of submission errors per field
fields[].fieldstring The name of the field that the error occurred on
fields[].messagestring The error message for the field
transformApiFieldNamesfunction <optional>
A function that maps the field names in the validation errors returned by the API to field names in the actual form.
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 formstring The name of the form
validationObject.<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.
wizardNamestring <optional>
null The name of the enhancedFormWizard this form is part of
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 formThe name of the form to submit
validationThe 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.
submitHandlerThe function to call when validation succeeds.
transformApiFieldNamesfunction <optional>
A function that maps the field names in the validation errors returned by the API to field names in the actual form.
submitSuccessHandlerfunction <optional>
A callback that will be called when the submitHandler function executes without error
submitFailHandlerfunction <optional>
A callback that will be called when there is a validation error or an error in execution of submitHandler
generalErrorMessagestring <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.
wizardRoutingAdapterisWizardStepBoolean 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
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 validationObject.<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.
formstring The name of the form to validate
fieldsArray.<string> <optional>
An array of field names to validate. If omitted, runs validation on all fields
Returns:
Function that will be handled by redux-thunk
- Type
- function
Type Definitions
-
ValidationConfig
-
- Source:
Properties:
Name Type Argument Default Description validateOnstring | Array.<string> <optional>
A string or array of strings that specifies on which event the validation should trigger. See ValidateOn.js for possible values.
validatorsArray.<ValidationRule> An array of validation rules to test this field for.
onlyValidateIfMountedboolean <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
-
ValidationRule
-
- 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
- Source:
Properties:
Name Type Description rulefunction 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:
messagestring A message that should be set as error message when this field is invalid.