diff --git a/src/reducers/form-actions-reducer.js b/src/reducers/form-actions-reducer.js index b8bbfee92..636781246 100644 --- a/src/reducers/form-actions-reducer.js +++ b/src/reducers/form-actions-reducer.js @@ -227,10 +227,11 @@ export function createFormActionsReducer(options) { case actionTypes.RESET_VALIDITY: { let validity = { ...fieldState.validity }; - let errors = { ...fieldState.errors }; + let errors; let valid; - if (action.omitKeys && action.omitKeys.length > 0) { + if (action.omitKeys && typeof fieldState.errors !== 'string') { + errors = { ...fieldState.errors }; action.omitKeys.forEach((key) => { delete validity[key]; delete errors[key]; diff --git a/test/field-actions-spec.js b/test/field-actions-spec.js index e914ee0d2..8db3524df 100644 --- a/test/field-actions-spec.js +++ b/test/field-actions-spec.js @@ -1148,16 +1148,16 @@ Object.keys(testContexts).forEach((testKey) => { assert.isTrue(isValid(actualState.foo)); }); - it('should handle omitKeys option beeing empty array for string type field errors', () => { + it('should handle omitKeys option beeing empty array', () => { const stateWithErrors = reducer( undefined, - actions.setErrors('test.foo', 'String error')); + actions.setErrors('test.foo', 'Foo')); assert.containSubset( stateWithErrors.foo, { validity: false, - errors: 'String error', + errors: 'Foo', }); assert.isFalse(isValid(stateWithErrors.foo)); @@ -1176,6 +1176,34 @@ Object.keys(testContexts).forEach((testKey) => { assert.isTrue(isValid(actualState.foo)); }); + it('should reset errors of a field with string errors', () => { + const stateWithErrors = reducer( + undefined, + actions.setErrors('test.foo', 'Foo')); + + assert.containSubset( + stateWithErrors.foo, + { + validity: false, + errors: 'Foo', + }); + + assert.isFalse(isValid(stateWithErrors.foo)); + + const actualState = reducer( + stateWithErrors, + actions.resetValidity('test.foo', ['foo', 'bar'])); + + assert.containSubset( + actualState.foo, + { + validity: {}, + errors: {}, + }); + + assert.isTrue(isValid(actualState.foo)); + }); + it('should reset the validity and errors of a form', () => { const stateWithErrors = reducer( undefined,