Skip to content

Commit

Permalink
feat: add submitCount to useFormActions and expose it in useForm
Browse files Browse the repository at this point in the history
  • Loading branch information
s8n11c committed Dec 29, 2024
1 parent 310301a commit b11cd03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/core/src/useForm/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function useForm<
}

const transactionsManager = useFormTransactions(ctx);
const { actions, isSubmitting, ...privateActions } = useFormActions<TInput, TOutput>(ctx, {
const { actions, isSubmitting,submitCount, ...privateActions } = useFormActions<TInput, TOutput>(ctx, {
disabled,
schema: props?.schema as StandardSchema<TInput, TOutput>,
scrollToInvalidFieldOnSubmit: props?.scrollToInvalidFieldOnSubmit ?? true,
Expand Down Expand Up @@ -213,6 +213,10 @@ export function useForm<
* Whether the form is disabled.
*/
isDisabled,
/**
* The number of times the form has been submitted.
*/
submitCount,
/**
* Whether the specified field is dirty.
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/useForm/useFormActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function useFormActions<TForm extends FormObject = FormObject, TOutput ex
{ disabled, schema, scrollToInvalidFieldOnSubmit }: FormActionsOptions<TForm, TOutput>,
) {
const isSubmitting = shallowRef(false);
const submitCount = shallowRef(0);
const [dispatchSubmit, onSubmitAttempt] = createEventDispatcher<void>('submit');
const {
validate: _validate,
Expand Down Expand Up @@ -107,6 +108,7 @@ export function useFormActions<TForm extends FormObject = FormObject, TOutput ex

const result = await onSuccess(withConsumers(output), { event: e, form: e?.target as HTMLFormElement });
isSubmitting.value = false;
submitCount.value += 1;

return result;
};
Expand Down Expand Up @@ -167,6 +169,7 @@ export function useFormActions<TForm extends FormObject = FormObject, TOutput ex
onValidationDispatch,
onValidationDone,
isSubmitting,
submitCount,
};
}

Expand Down

0 comments on commit b11cd03

Please sign in to comment.