CB-4335 added to useForm submit events handling

This commit is contained in:
s.teleshev
2023-12-06 13:49:48 +01:00
parent 9bc07dd774
commit 7abe6eface
2 changed files with 4 additions and 4 deletions
@@ -21,7 +21,7 @@ export interface IChangeData {
export interface IFormContext {
ref: HTMLFormElement | null;
onValidate: SyncExecutor;
onSubmit: SyncExecutor;
onSubmit: SyncExecutor<SubmitEvent | undefined>;
onChange: IExecutor<IChangeData>;
parent: IFormContext | null;
disableEnterSubmit: boolean;
@@ -22,7 +22,7 @@ interface IOptions {
export function useForm(options?: IOptions): IFormContext {
let parentForm = useContext(FormContext);
const [submittingExecutor] = useState(() => new SyncExecutor());
const [submittingExecutor] = useState(() => new SyncExecutor<SubmitEvent | undefined>());
const [validationExecutor] = useState(() => new SyncExecutor());
const [changeExecutor] = useState(() => new Executor<IChangeData>());
@@ -49,7 +49,7 @@ export function useForm(options?: IOptions): IFormContext {
useExecutor({
executor: submittingExecutor,
handlers: [() => options?.onSubmit?.()],
handlers: [event => options?.onSubmit?.(event)],
});
const context = useObjectRef<IFormContext>(
@@ -93,7 +93,7 @@ export function useForm(options?: IOptions): IFormContext {
event?.preventDefault();
if (this.validate()) {
this.onSubmit.execute();
this.onSubmit.execute(event);
}
}
},