@prefecthq/prefect-ui-library
Version:
This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.
29 lines (22 loc) • 742 B
text/typescript
import { scrollToValidationError } from '@prefecthq/prefect-design'
import { useForm as useVeeForm } from 'vee-validate'
export const useForm: typeof useVeeForm = (options) => {
const { handleSubmit, ...rest } = useVeeForm(options)
const submit: typeof handleSubmit = (onSuccess, onError) => {
const onSuccessWrapped: typeof onSuccess = (values, context) => {
return onSuccess(values, context)
}
const onErrorWrapped: typeof onError = (context) => {
if (onError) {
onError(context)
}
scrollToValidationError()
}
return handleSubmit(onSuccessWrapped, onErrorWrapped)
}
submit.withControlled = handleSubmit.withControlled
return {
...rest,
handleSubmit: submit,
}
}