Skip to content

Commit

Permalink
Merge pull request #24 from panic175/master
Browse files Browse the repository at this point in the history
Added proxy method `reset`
  • Loading branch information
NetanelBasal committed Feb 22, 2021
2 parents 965c3a1 + 091723e commit 0ee5eff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
34 changes: 28 additions & 6 deletions 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');

Expand Down Expand Up @@ -266,6 +266,28 @@ export class NgFormsManager<FormsState = any> {
}
}

/**
*
* @example
*
* A proxy to the original `reset` method
*
* manager.reset('login', { email: '' });
*
*/
reset<T extends keyof FormsState>(
name: T,
value?: Partial<FormsState[T]>,
options?: {
onlySelf?: boolean;
emitEvent?: boolean;
}
) {
if (this.instances$$.has(name)) {
this.instances$$.get(name).reset(value, options);
}
}

/**
*
* Sets the initial value for a control
Expand Down

0 comments on commit 0ee5eff

Please sign in to comment.