Skip to content

Commit 0ee5eff

Browse files
authored
Merge pull request #24 from panic175/master
Added proxy method `reset`
2 parents 965c3a1 + 091723e commit 0ee5eff

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ formsManager.patchValue('onboarding', value, options);
171171
formsManager.setValue('onboarding', value, options);
172172
```
173173

174+
- `reset()` - A proxy to the original `reset` method
175+
176+
```ts
177+
formsManager.reset('onboarding', value, options);
178+
```
179+
174180
- `markAllAsTouched()` - A proxy to the original `markAllAsTouched` method
175181

176182
```ts

projects/ngneat/forms-manager/src/lib/forms-manager.ts

+28-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Inject, Injectable, Optional } from '@angular/core';
2-
import { AbstractControl, FormGroup, FormArray } from '@angular/forms';
3-
import { coerceArray, filterControlKeys, filterNil, isBrowser, mergeDeep } from './utils';
2+
import { AbstractControl, FormArray, FormGroup } from '@angular/forms';
43
import { EMPTY, merge, Observable, Subject, Subscription, timer } from 'rxjs';
5-
import { debounce, distinctUntilChanged, filter, map, mapTo, tap } from 'rxjs/operators';
4+
import { debounce, distinctUntilChanged, filter, map, mapTo } from 'rxjs/operators';
5+
import { deleteControl, findControl, handleFormArray, toStore } from './builders';
6+
import { Config, NgFormsManagerConfig, NG_FORMS_MANAGER_CONFIG } from './config';
67
import { FormsStore } from './forms-manager.store';
7-
import { Control, ControlFactory, FormKeys, HashMap, UpsertConfig } from './types';
8-
import { Config, NG_FORMS_MANAGER_CONFIG, NgFormsManagerConfig } from './config';
98
import { isEqual } from './isEqual';
10-
import { deleteControl, findControl, handleFormArray, toStore } from './builders';
9+
import { Control, ControlFactory, FormKeys, HashMap, UpsertConfig } from './types';
10+
import { coerceArray, filterControlKeys, filterNil, isBrowser, mergeDeep } from './utils';
1111

1212
const NO_DEBOUNCE = Symbol('NO_DEBOUNCE');
1313

@@ -266,6 +266,28 @@ export class NgFormsManager<FormsState = any> {
266266
}
267267
}
268268

269+
/**
270+
*
271+
* @example
272+
*
273+
* A proxy to the original `reset` method
274+
*
275+
* manager.reset('login', { email: '' });
276+
*
277+
*/
278+
reset<T extends keyof FormsState>(
279+
name: T,
280+
value?: Partial<FormsState[T]>,
281+
options?: {
282+
onlySelf?: boolean;
283+
emitEvent?: boolean;
284+
}
285+
) {
286+
if (this.instances$$.has(name)) {
287+
this.instances$$.get(name).reset(value, options);
288+
}
289+
}
290+
269291
/**
270292
*
271293
* Sets the initial value for a control

0 commit comments

Comments
 (0)