diff --git a/webapp/packages/core-ui/src/Form/FormBaseService.ts b/webapp/packages/core-ui/src/Form/FormBaseService.ts index 6ee77040d9..783aa4898b 100644 --- a/webapp/packages/core-ui/src/Form/FormBaseService.ts +++ b/webapp/packages/core-ui/src/Form/FormBaseService.ts @@ -23,6 +23,7 @@ export class FormBaseService = IFormPr readonly onConfigure: IExecutorHandlersCollection>; readonly onFillDefaultConfig: IExecutorHandlersCollection>; readonly onPrepareConfig: IExecutorHandlersCollection; + readonly onFormat: IExecutorHandlersCollection>; readonly onValidate: IExecutorHandlersCollection>; readonly onSubmit: IExecutorHandlersCollection>; readonly onState: IExecutorHandlersCollection; @@ -33,6 +34,7 @@ export class FormBaseService = IFormPr this.onConfigure = new ExecutorHandlersCollection(); this.onFillDefaultConfig = new ExecutorHandlersCollection(); this.onPrepareConfig = new ExecutorHandlersCollection(); + this.onFormat = new ExecutorHandlersCollection(); this.onValidate = new ExecutorHandlersCollection(); this.onSubmit = new ExecutorHandlersCollection(); this.onState = new ExecutorHandlersCollection(); diff --git a/webapp/packages/core-ui/src/Form/FormPart.ts b/webapp/packages/core-ui/src/Form/FormPart.ts index b57ccee1a1..b6ce21dd99 100644 --- a/webapp/packages/core-ui/src/Form/FormPart.ts +++ b/webapp/packages/core-ui/src/Form/FormPart.ts @@ -35,6 +35,7 @@ export abstract class FormPart implements IFormPar this.formState.submitTask.addHandler(executorHandlerFilter(() => this.isLoaded(), this.save.bind(this))); this.formState.configureTask.addHandler(executorHandlerFilter(() => this.isLoaded(), this.configure.bind(this))); + this.formState.formatTask.addHandler(executorHandlerFilter(() => this.isLoaded(), this.format.bind(this))); this.formState.validationTask.addHandler(executorHandlerFilter(() => this.isLoaded(), this.validate.bind(this))); makeObservable(this, { @@ -141,6 +142,7 @@ export abstract class FormPart implements IFormPar } protected configure(data: IFormState, contexts: IExecutionContextProvider>): void | Promise {} + protected format(data: IFormState, contexts: IExecutionContextProvider>): void | Promise {} protected validate(data: IFormState, contexts: IExecutionContextProvider>): void | Promise {} protected abstract loader(): Promise; diff --git a/webapp/packages/core-ui/src/Form/FormState.ts b/webapp/packages/core-ui/src/Form/FormState.ts index 800a52e727..41541615ab 100644 --- a/webapp/packages/core-ui/src/Form/FormState.ts +++ b/webapp/packages/core-ui/src/Form/FormState.ts @@ -40,6 +40,7 @@ export class FormState implements IFormState { readonly formStateTask: IExecutor; readonly fillDefaultConfigTask: IExecutor>; readonly submitTask: IExecutor>; + readonly formatTask: IExecutor>; readonly validationTask: IExecutor>; constructor(app: App, service: FormBaseService, state: TState) { @@ -67,8 +68,11 @@ export class FormState implements IFormState { this.fillDefaultConfigTask = new Executor(this as IFormState, () => true); this.fillDefaultConfigTask.addCollection(service.onFillDefaultConfig).next(this.formStateTask, form => form.state); + this.formatTask = new Executor(this as IFormState, () => true); + this.formatTask.addCollection(service.onFormat); + this.validationTask = new Executor(this as IFormState, () => true); - this.validationTask.addCollection(service.onValidate); + this.validationTask.addCollection(service.onValidate).before(this.formatTask); this.submitTask = new Executor(this as IFormState, () => true); this.submitTask.addCollection(service.onSubmit).before(this.validationTask); diff --git a/webapp/packages/core-ui/src/Form/IFormState.ts b/webapp/packages/core-ui/src/Form/IFormState.ts index 2afc2b1d96..148c953081 100644 --- a/webapp/packages/core-ui/src/Form/IFormState.ts +++ b/webapp/packages/core-ui/src/Form/IFormState.ts @@ -33,6 +33,7 @@ export interface IFormState extends ILoadableState { readonly formStateTask: IExecutor; readonly fillDefaultConfigTask: IExecutor>; readonly submitTask: IExecutor>; + readonly formatTask: IExecutor>; readonly validationTask: IExecutor>; setMode(mode: FormMode): this;