diff --git a/README.md b/README.md index df2a4ad..8dee351 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,12 @@ formsManager.patchValue('onboarding', value, options); formsManager.setValue('onboarding', value, options); ``` +- `reset()` - A proxy to the original `reset` method + +```ts +formsManager.reset('onboarding', value, options); +``` + - `markAllAsTouched()` - A proxy to the original `markAllAsTouched` method ```ts diff --git a/projects/ngneat/forms-manager/src/lib/forms-manager.ts b/projects/ngneat/forms-manager/src/lib/forms-manager.ts index cb8c508..342f86f 100644 --- a/projects/ngneat/forms-manager/src/lib/forms-manager.ts +++ b/projects/ngneat/forms-manager/src/lib/forms-manager.ts @@ -1,13 +1,13 @@ import { Inject, Injectable, Optional } from '@angular/core'; -import { AbstractControl, FormGroup, FormArray } from '@angular/forms'; -import { coerceArray, filterControlKeys, filterNil, isBrowser, mergeDeep } from './utils'; +import { AbstractControl, FormArray, FormGroup } from '@angular/forms'; import { EMPTY, merge, Observable, Subject, Subscription, timer } from 'rxjs'; -import { debounce, distinctUntilChanged, filter, map, mapTo, tap } from 'rxjs/operators'; +import { debounce, distinctUntilChanged, filter, map, mapTo } from 'rxjs/operators'; +import { deleteControl, findControl, handleFormArray, toStore } from './builders'; +import { Config, NgFormsManagerConfig, NG_FORMS_MANAGER_CONFIG } from './config'; import { FormsStore } from './forms-manager.store'; -import { Control, ControlFactory, FormKeys, HashMap, UpsertConfig } from './types'; -import { Config, NG_FORMS_MANAGER_CONFIG, NgFormsManagerConfig } from './config'; import { isEqual } from './isEqual'; -import { deleteControl, findControl, handleFormArray, toStore } from './builders'; +import { Control, ControlFactory, FormKeys, HashMap, UpsertConfig } from './types'; +import { coerceArray, filterControlKeys, filterNil, isBrowser, mergeDeep } from './utils'; const NO_DEBOUNCE = Symbol('NO_DEBOUNCE'); @@ -266,6 +266,28 @@ export class NgFormsManager { } } + /** + * + * @example + * + * A proxy to the original `reset` method + * + * manager.reset('login', { email: '' }); + * + */ + reset( + name: T, + value?: Partial, + options?: { + onlySelf?: boolean; + emitEvent?: boolean; + } + ) { + if (this.instances$$.has(name)) { + this.instances$$.get(name).reset(value, options); + } + } + /** * * Sets the initial value for a control