@studiohyperdrive/ngx-forms
Version:
An Angular package to help with complex forms and their validation.
123 lines (122 loc) • 4.68 kB
TypeScript
import { ChangeDetectorRef, OnDestroy, QueryList } from '@angular/core';
import { AbstractControl, ControlValueAccessor, FormControl, ValidationErrors } from '@angular/forms';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { FormAccessorControlsEntity, FormStateOptionsEntity } from '../../interfaces';
import { DataFormAccessor } from '../data-form/data-form.accessor';
import { FormAccessor } from '../form/form.accessor';
import * as i0 from "@angular/core";
export declare abstract class NgxFormsControlValueAccessor<DataType = unknown, FormAccessorFormType extends AbstractControl = FormControl, FormValueType = DataType> implements ControlValueAccessor, OnDestroy {
/**
* The Injector needed in the constructor
*/
private readonly injector;
/**
* The ChangeDetector reference
*/
readonly cdRef: ChangeDetectorRef;
/**
* A subject to hold the parent control
*/
private readonly parentControlSubject$;
/**
* A reference to the control tied to this control value accessor
*/
protected readonly parentControl$: Observable<AbstractControl>;
/**
* Inner form to write to
*/
form: FormAccessorFormType;
/**
* Whether the first setDisable has run
*/
protected initialSetDisableHasRun: boolean;
/**
* On destroy flow handler
*/
protected readonly destroy$: Subject<unknown>;
/**
* Subject to check whether the form is initialized
*/
protected readonly initializedSubject$: BehaviorSubject<boolean>;
/**
* Whether or not we want to emit a value when we use the disableFields, by default this will emit
*
* @param keys - Keys we're about to disable
*/
protected emitValueWhenDisableFieldsUsingInput?(keys: FormAccessorControlsEntity<FormAccessorFormType>[]): boolean;
/**
* A list of all DataFormAccessors en FormAccessors of this component
*/
accessors: QueryList<DataFormAccessor | FormAccessor>;
/**
* Keys of the fields we wish to disable.
* By default this will emit a valueChanges, this can be overwritten by the emitValueWhenDisableFieldsUsingInput in the Accessor
*
* @memberof FormAccessor
*/
set disableFields(keys: FormAccessorControlsEntity<FormAccessorFormType>[]);
/**
* Whether we want to skip the first setDisable (https://github.com/angular/angular/pull/47576).
* By default, this is true
*/
skipInitialSetDisable: boolean;
/**
* Stream to know whether the form has been initialized
*/
readonly initialized$: Observable<boolean>;
constructor();
/**
* Sets up the ControlValueAccessor connectors
*/
onTouch: Function;
onChange: Function;
registerOnChange(fn: any): void;
registerOnTouched(fn: any): void;
/**
* Writes value to the inner form
*
* @param value - Value to patch in the inner form
*/
writeValue(value: DataType | undefined | null): void;
/**
* Mark all controls of the form as touched
*/
markAsTouched(options?: FormStateOptionsEntity): void;
/**
* Mark all controls of the form as dirty
*/
markAsDirty(options?: FormStateOptionsEntity): void;
/**
* Mark all controls of the form as pristine
*/
markAsPristine(options?: FormStateOptionsEntity): void;
/**
* Update the value and validity of the provided form
*/
updateAllValueAndValidity(options: FormStateOptionsEntity): void;
/**
* Validates the inner form
*/
validate(): ValidationErrors | null;
/**
* Disables/enables the inner form based on the passed value
*
* @param isDisabled - Whether or not the form should be disabled
*/
setDisabledState(isDisabled: boolean): void;
/**
* Optional method to map the inner form value to an outer form specific format
*
* @param value - Value from the form
*/
onChangeMapper?(value: Partial<FormValueType>): DataType;
/**
* Optional method to map the outer form value to an inner form specific format
*
* @param value - Value from the form
*/
onWriteValueMapper?(value: DataType): FormValueType;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<NgxFormsControlValueAccessor<any, any, any>, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NgxFormsControlValueAccessor<any, any, any>, never, never, { "disableFields": { "alias": "disableFields"; "required": false; }; "skipInitialSetDisable": { "alias": "skipInitialSetDisable"; "required": false; }; }, { "initialized$": "initialized$"; }, never, never, true, never>;
}