Verified Commit 4fc75a33 authored by Merzough Münker's avatar Merzough Münker
Browse files

feat(forms): add initial state support to submit and load methods

Extended `FormSubmitMethod` and `FormLoadMethod` to include `initial` state as an optional parameter. Updated `FormDirective` to leverage the `initial` state for more flexible form handling and submission logic.
parent ad83fbc9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -509,7 +509,7 @@ export class FormDirective<T = any>
      this.submitting$.enable();
      this.submitError$.next(null);
      try {
        const resultOrPromise = this.submitMethod.call(value, this.context());
        const resultOrPromise = this.submitMethod.call(value, this.context(), this.initial());
        if (isPromise(resultOrPromise)) {
          resultOrPromise
            .then((result) => {
+4 −4
Original line number Diff line number Diff line
@@ -3,12 +3,12 @@ import {
  MethodWithParameters,
} from '@rxap/pattern';

export interface FormSubmitMethod<T> extends MethodWithParameters<any, T> {
  call(parameters: T, context?: unknown): any | Promise<any>;
export interface FormSubmitMethod<FormSate = any, Context = any, Initial = any> extends MethodWithParameters<any, FormSate> {
  call(parameters: FormSate, context?: Context | null, initial?: Initial | null): any | Promise<any>;
}

export interface FormLoadMethod<T = any> extends Method<T> {
  call(data: { context: unknown | null, initial: unknown | null }): T | Promise<T>;
export interface FormLoadMethod<FormState = any, Context = any, Initial = any> extends Method<FormState> {
  call(data: { context: Context | null, initial: Initial | null }): FormState | Promise<FormState>;
}

export interface FormLoadFailedMethod extends MethodWithParameters {