ngx-forms-typed
Version:
Angular Forms Typed provides types and helper functions fully compatible with original Angular forms
32 lines (31 loc) • 1.51 kB
TypeScript
import { AbstractControl, UntypedFormArray, UntypedFormGroup } from '@angular/forms';
export type Methods = keyof Pick<AbstractControl, 'markAsDirty' | 'markAsTouched' | 'updateValueAndValidity' | 'disable' | 'enable' | 'markAsUntouched' | 'markAsPristine' | 'markAsPending'>;
/**
* Does an aggregate action on a form's controls.
*
* @param form the form to whose controls we want to influence
*
* For example we want to call `markAsTouched` on each control in a form, for visualizing validation purposes.
* @example
* const form = new FormGroup({name: ..., email: ..., address: ..., ...});
*
* forEachControlIn(form).call('markAsTouched') - will iterate over all controls and call that method
*/
export declare function forEachControlIn(form: UntypedFormGroup | UntypedFormArray): {
/**
* Enumerate which methods to call.
* @param methods which methods to call - as typed string enum
*
* @example
*
* forEachControlIn(form).call('markAsPristine', 'markAsTouched', 'disable')
*/
call(...methods: Methods[]): any;
markAsDirtySimultaneouslyWith(c: AbstractControl): any;
markAsTouchedSimultaneouslyWith(c: AbstractControl, touchIsChildInitiated?: () => boolean): any;
/**
* Get the errors in the controls from our form and append their errors to the `form` (in forEachControlIn(form) form)
* @param parentControl the control that should be invalid if on of our controls is
*/
addValidatorsTo(parentControl: AbstractControl): any;
};