Skip to content

Commit dfbcbd8

Browse files
feat: add onBeforeSumbit hook on multi step form
1 parent 7c93b7b commit dfbcbd8

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

layers/tairo/composables/multi-step-form.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface MultiStepFormConfig<
2020
initialState: MaybeRefOrGetter<DATA>
2121
steps: StepForm<DATA, META>[]
2222

23+
onBeforeSubmit?: (data: DATA, ctx: MultiStepFormContext<DATA, META>) => Promise<void> | void
2324
onSubmit?: (data: DATA, ctx: MultiStepFormContext<DATA, META>) => Promise<void> | void
2425
onError?: (
2526
error: any,
@@ -216,17 +217,20 @@ export function provideMultiStepForm<
216217
return
217218
}
218219

219-
const nextStep = getNextStep()
220-
221-
// go to the next step if there is one
222-
if (nextStep) {
223-
await goToStep(nextStep)
224-
loading.value = false
225-
return
226-
}
227-
228220
// submit the form otherwise
229221
try {
222+
if (rules.onBeforeSubmit) {
223+
await rules.onBeforeSubmit(data.value as DATA, context)
224+
}
225+
226+
const nextStep = getNextStep()
227+
228+
// go to the next step if there is one
229+
if (nextStep) {
230+
await goToStep(nextStep)
231+
return
232+
}
233+
230234
if (rules.onSubmit) {
231235
await rules.onSubmit(data.value as DATA, context)
232236
}

layers/tairo/plugins/directives.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
66
*/
77
nuxtApp.vueApp.directive<HTMLElement, boolean | undefined>('focus', {
88
mounted(el, { value }) {
9-
console.log('v-focus?', value)
109
if (value === false) {
1110
return
1211
}

0 commit comments

Comments
 (0)