Skip to content

Commit 749c1b5

Browse files
committed
fix: empty groups and arrays are now always enabled instead of disabled and therefore errors can now be set on empty groups and arrays
1 parent 6e83b95 commit 749c1b5

File tree

6 files changed

+398
-21
lines changed

6 files changed

+398
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
## ngrx-forms Changelog
22

3-
<a name="2.1.3"></a>
4-
### 2.1.3
3+
<a name="2.2.0"></a>
4+
### 2.2.0
5+
6+
#### Breaking Changes
7+
8+
* empty groups and arrays are now always enabled instead of disabled and therefore errors can now be set on empty groups and arrays (note that this is only a minor breaking change and only applies in edge cases and therefore this fix is included in a new minor instead of a new major version), closes [#37](https://github.com/MrWolfZ/ngrx-forms/issues/37)
59

610
#### Bugfixes
711

src/array/reducer/set-errors.spec.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ describe(`form array ${setErrorsReducer.name}`, () => {
4646
expect(resultState).toBe(INITIAL_STATE);
4747
});
4848

49-
// will be fixed as part of another bugfix
50-
// it('should update state if array is empty', () => {
51-
// const errors = { required: true };
52-
// const state = createFormArrayState<string>('test ID', []);
53-
// const resultState = setErrorsReducer(state, new SetErrorsAction(FORM_CONTROL_ID, errors));
54-
// expect(resultState.errors).toEqual(errors);
55-
// expect(resultState.isValid).toBe(false);
56-
// expect(resultState.isInvalid).toBe(true);
57-
// });
49+
it('should update state if array is empty', () => {
50+
const errors = { required: true };
51+
const state = createFormArrayState<string>('test ID', []);
52+
const resultState = setErrorsReducer(state, new SetErrorsAction(FORM_CONTROL_ID, errors));
53+
expect(resultState.errors).toEqual(errors);
54+
expect(resultState.isValid).toBe(false);
55+
expect(resultState.isInvalid).toBe(true);
56+
});
5857

5958
it('should keep async errors', () => {
6059
const syncErrors = { required: true };

src/group/reducer/set-errors.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SetErrorsAction } from '../../actions';
2+
import { createFormGroupState } from '../../state';
23
import { setErrorsReducer } from './set-errors';
34
import {
45
FORM_CONTROL_ID,
@@ -47,6 +48,15 @@ describe(`form group ${setErrorsReducer.name}`, () => {
4748
expect(resultState).toBe(INITIAL_STATE);
4849
});
4950

51+
it('should update state if group is empty', () => {
52+
const errors = { required: true };
53+
const state = createFormGroupState('test ID', {});
54+
const resultState = setErrorsReducer(state, new SetErrorsAction(FORM_CONTROL_ID, errors));
55+
expect(resultState.errors).toEqual(errors);
56+
expect(resultState.isValid).toBe(false);
57+
expect(resultState.isInvalid).toBe(true);
58+
});
59+
5060
it('should keep async errors', () => {
5161
const syncErrors = { required: true };
5262
const asyncErrors = { $required: true };

0 commit comments

Comments
 (0)