Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/reducers/form-actions-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
34 changes: 31 additions & 3 deletions test/field-actions-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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,
Expand Down