Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 2fb5db0

Browse files
authored
Merge pull request #1117 from marcinm2h/1116
Fix 1116
2 parents e99caae + ad53a46 commit 2fb5db0

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/reducers/form-actions-reducer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ export function createFormActionsReducer(options) {
227227

228228
case actionTypes.RESET_VALIDITY: {
229229
let validity = { ...fieldState.validity };
230-
let errors = { ...fieldState.errors };
230+
let errors;
231231
let valid;
232232

233-
if (action.omitKeys && action.omitKeys.length > 0) {
233+
if (action.omitKeys && typeof fieldState.errors !== 'string') {
234+
errors = { ...fieldState.errors };
234235
action.omitKeys.forEach((key) => {
235236
delete validity[key];
236237
delete errors[key];

test/field-actions-spec.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,16 +1148,16 @@ Object.keys(testContexts).forEach((testKey) => {
11481148
assert.isTrue(isValid(actualState.foo));
11491149
});
11501150

1151-
it('should handle omitKeys option beeing empty array for string type field errors', () => {
1151+
it('should handle omitKeys option beeing empty array', () => {
11521152
const stateWithErrors = reducer(
11531153
undefined,
1154-
actions.setErrors('test.foo', 'String error'));
1154+
actions.setErrors('test.foo', 'Foo'));
11551155

11561156
assert.containSubset(
11571157
stateWithErrors.foo,
11581158
{
11591159
validity: false,
1160-
errors: 'String error',
1160+
errors: 'Foo',
11611161
});
11621162

11631163
assert.isFalse(isValid(stateWithErrors.foo));
@@ -1176,6 +1176,34 @@ Object.keys(testContexts).forEach((testKey) => {
11761176
assert.isTrue(isValid(actualState.foo));
11771177
});
11781178

1179+
it('should reset errors of a field with string errors', () => {
1180+
const stateWithErrors = reducer(
1181+
undefined,
1182+
actions.setErrors('test.foo', 'Foo'));
1183+
1184+
assert.containSubset(
1185+
stateWithErrors.foo,
1186+
{
1187+
validity: false,
1188+
errors: 'Foo',
1189+
});
1190+
1191+
assert.isFalse(isValid(stateWithErrors.foo));
1192+
1193+
const actualState = reducer(
1194+
stateWithErrors,
1195+
actions.resetValidity('test.foo', ['foo', 'bar']));
1196+
1197+
assert.containSubset(
1198+
actualState.foo,
1199+
{
1200+
validity: {},
1201+
errors: {},
1202+
});
1203+
1204+
assert.isTrue(isValid(actualState.foo));
1205+
});
1206+
11791207
it('should reset the validity and errors of a form', () => {
11801208
const stateWithErrors = reducer(
11811209
undefined,

0 commit comments

Comments
 (0)