Skip to main content

FormModal

A modal dialog that combines form state, mutation execution, and submit/reset actions.

VEF-specific component. Moved from @vef-framework-react/starter to @vef-framework-react/components in v2.1.6.

When to Use

  • Create and edit forms that open in a modal dialog.
  • Any form that submits via a MutationFunction.

Basic Usage

import { FormModal, useForm } from '@vef-framework-react/components';

interface UserForm {
name: string;
email: string;
}

export default function CreateUserModal({ open, onClose }) {
return (
<FormModal<UserForm>
open={open}
title="Create User"
defaultValues={{ name: '', email: '' }}
mutationFn={createUser}
mutationMeta={{ invalidates: [[findUserPage.key]] }}
afterSubmit={() => onClose()}
onClose={onClose}
>
{(form) => (
<>
<form.AppField name="name">
{(field) => <field.Input label="Name" required />}
</form.AppField>
<form.AppField name="email">
{(field) => <field.Input label="Email" required />}
</form.AppField>
</>
)}
</FormModal>
);
}

API

PropTypeDefaultDescription
openbooleanfalseWhether the modal is visible
titleReactNodeModal title
widthstring | numberModal width
draggablebooleantrueWhether the modal can be dragged
defaultValuesTValuesInitial form values
disabledbooleanfalseDisable the form
mutationFnMutationFunction<ApiResult<TData>, TValues>Mutation to execute on submit
mutationMetaMutationMetaMutation metadata (e.g. invalidates)
beforeSubmit(values) => Awaitable<TValues>Transform values before submission
afterSubmit(values, data) => Awaitable<void>Called after successful submission
onSubmit(values) => Awaitable<void>Custom submit handler (alternative to mutationFn)
onReset(defaultValues?) => voidCalled on form reset
onClose() => voidCalled when modal closes
renderActions(formApi) => ReactNodeCustom footer actions; return null to hide footer
submitButtonPropsSubmitButtonPropsSubmit button customization
resetButtonPropsResetButtonProps | falseReset button customization; false to hide
childrenReactNode | (formApi) => ReactNodeForm content