Skip to content

Commit 5089cb6

Browse files
feat(Form): add loadingAuto prop
1 parent f273a3e commit 5089cb6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/runtime/components/Form.vue

+10-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export interface FormProps<T extends object> {
3939
* @defaultValue `true`
4040
*/
4141
transform?: boolean
42+
/**
43+
* When `true`, all form elements will be disabled on `@submit` event.
44+
* This will cause any focused input elements to lose their focus state.
45+
* @defaultValue `true`
46+
*/
47+
loadingAuto?: boolean
4248
class?: any
4349
onSubmit?: ((event: FormSubmitEvent<T>) => void | Promise<void>) | (() => void | Promise<void>)
4450
}
@@ -65,7 +71,8 @@ const props = withDefaults(defineProps<FormProps<T>>(), {
6571
return ['input', 'blur', 'change'] as FormInputEvents[]
6672
},
6773
validateOnInputDelay: 300,
68-
transform: true
74+
transform: true,
75+
loadingAuto: true
6976
})
7077
7178
const emits = defineEmits<FormEmits<T>>()
@@ -211,7 +218,6 @@ provide(formLoadingInjectionKey, readonly(loading))
211218
212219
async function onSubmitWrapper(payload: Event) {
213220
const event = payload as FormSubmitEvent<any>
214-
const activeElement = document.activeElement as HTMLElement
215221
216222
loading.value = true
217223
@@ -232,11 +238,11 @@ async function onSubmitWrapper(payload: Event) {
232238
emits('error', errorEvent)
233239
} finally {
234240
loading.value = false
235-
setTimeout(() => activeElement?.focus(), 0)
236241
}
237242
}
238243
239-
const disabled = computed(() => props.disabled || loading.value)
244+
const isLoading = computed(() => loading.value && props.loadingAuto)
245+
const disabled = computed(() => props.disabled || isLoading.value)
240246
241247
provide(formOptionsInjectionKey, computed(() => ({
242248
disabled: disabled.value,

0 commit comments

Comments
 (0)