@rxap/forms
Version:
This package provides a set of tools and directives to simplify working with Angular forms, including reactive forms, custom validators, and form directives for handling loading, submitting, and error states. It offers decorators for defining forms and co
63 lines (62 loc) • 4.8 kB
TypeScript
import { ChangeDetectorRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { FormGroupDirective } from '@angular/forms';
import { ToggleSubject } from '@rxap/rxjs';
import { LoadingIndicatorService } from '@rxap/services';
import { BehaviorSubject } from 'rxjs';
import { RxapFormBuilder } from '../form-builder';
import { RxapFormGroup } from '../form-group';
import { FormDefinition } from '../model';
import { FormLoadFailedMethod, FormLoadMethod, FormLoadSuccessfulMethod, FormSubmitFailedMethod, FormSubmitMethod, FormSubmitSuccessfulMethod } from './models';
import * as i0 from "@angular/core";
export declare class FormDirective<T = any> extends FormGroupDirective implements OnInit, OnChanges, OnDestroy {
readonly cdr: ChangeDetectorRef;
protected readonly formDefinitionBuilder: RxapFormBuilder | null;
protected readonly loadingIndicatorService: LoadingIndicatorService | null;
form: RxapFormGroup<T>;
readonly initial: import("@angular/core").ModelSignal<T | null>;
readonly context: import("@angular/core").ModelSignal<unknown>;
/**
* Emits when the submit method is executed without errors. The result of the
* submit method is passed as event object.
*
* If no submit method is defined then emit after the submit button
* is clicked.
*/
rxapSubmit: EventEmitter<any>;
invalidSubmit: EventEmitter<Record<string, any>>;
submitSuccessful$: EventEmitter<any>;
get submitting(): boolean;
get submitError(): Error | null;
get loading(): boolean;
get loaded(): boolean;
get loadingError(): Error | null;
set useFormDefinition(value: FormDefinition<T> | '');
get formDefinition(): FormDefinition<T>;
readonly submitting$: ToggleSubject;
readonly submitError$: BehaviorSubject<Error | null>;
readonly loading$: ToggleSubject;
readonly loaded$: ToggleSubject;
readonly loadingError$: BehaviorSubject<Error | null>;
protected _formDefinition: FormDefinition<T>;
submitMethod: FormSubmitMethod<any> | null;
loadMethod: FormLoadMethod | null;
loadFailedMethod: FormLoadFailedMethod | null;
loadSuccessfulMethod: FormLoadSuccessfulMethod | null;
submitFailedMethod: FormSubmitFailedMethod | null;
submitSuccessfulMethod: FormSubmitSuccessfulMethod | null;
private _autoSubmitSubscription;
constructor(cdr: ChangeDetectorRef, formDefinition?: FormDefinition | null, submitMethod?: FormSubmitMethod<any> | null, loadMethod?: FormLoadMethod | null, loadFailedMethod?: FormLoadFailedMethod | null, loadSuccessfulMethod?: FormLoadSuccessfulMethod | null, submitFailedMethod?: FormSubmitFailedMethod | null, submitSuccessfulMethod?: FormSubmitSuccessfulMethod | null, formDefinitionBuilder?: RxapFormBuilder | null, loadingIndicatorService?: LoadingIndicatorService | null, context?: unknown, initial?: T | null);
ngOnChanges(changes: SimpleChanges): void;
ngOnInit(): void;
onSubmit($event: Event): boolean;
protected loadInitialState(form: RxapFormGroup): void;
protected loadSuccessful(value: any): void;
protected loadFailed(error: Error): void;
protected getSubmitValue(): T;
protected submit(): void;
protected submitFailed(error: Error): void;
protected submitSuccessful(value: any): void;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<FormDirective<any>, [null, { optional: true; }, { optional: true; skipSelf: true; }, { optional: true; skipSelf: true; }, { optional: true; skipSelf: true; }, { optional: true; skipSelf: true; }, { optional: true; skipSelf: true; }, { optional: true; skipSelf: true; }, { optional: true; skipSelf: true; }, { optional: true; }, { optional: true; }, { optional: true; }]>;
static ɵdir: i0.ɵɵDirectiveDeclaration<FormDirective<any>, "form[rxapForm]:not([formGroup]):not([ngForm]),rxap-form,form[rxapForm]", ["rxapForm"], { "initial": { "alias": "initial"; "required": false; "isSignal": true; }; "context": { "alias": "context"; "required": false; "isSignal": true; }; "useFormDefinition": { "alias": "rxapForm"; "required": false; }; "submitMethod": { "alias": "submitMethod"; "required": false; }; "loadMethod": { "alias": "loadMethod"; "required": false; }; "loadFailedMethod": { "alias": "loadFailedMethod"; "required": false; }; "loadSuccessfulMethod": { "alias": "loadSuccessfulMethod"; "required": false; }; "submitFailedMethod": { "alias": "submitFailedMethod"; "required": false; }; "submitSuccessfulMethod": { "alias": "submitSuccessfulMethod"; "required": false; }; }, { "ngSubmit": "ngSubmit"; "initial": "initialChange"; "context": "contextChange"; "rxapSubmit": "rxapSubmit"; "invalidSubmit": "invalidSubmit"; "submitSuccessful$": "submitSuccessful"; }, never, never, true, never>;
}