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 } 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​

The props type is exported as FormModalProps.

The draggable default can be overridden application-wide with ConfigProvider.components.FormModal; a prop passed to this component still wins.

PropTypeDefaultDescription
openbooleanfalseWhether the modal is visible
titleReactNode—Modal title
widthstring | number—Modal width
draggablebooleantrue, overridable by ConfigProvider.components.FormModalWhether the modal can be dragged
defaultValuesTValues—Initial form values
disabledbooleanfalseDisable the form
formComponentElementType"form"Element type for the inner form wrapper
formLayoutFormLayout—Layout of the form items inside the modal — layout ('horizontal' | 'vertical'), labelAlign and labelWidth. Defaults to the horizontal, right-aligned label layout (see Form)
mutationFnMutationFunction<ApiResult<TData>, TValues>—Mutation to execute on submit
mutationMetaMutationMeta—Mutation 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?) => void—Called on form reset
onClose() => void—Called when modal closes
renderActions(formApi, defaults: { submitButton, resetButton }) => ReactNode—Custom footer actions; defaults carries the default submit/reset buttons to reuse alongside custom ones; return null to hide footer
submitButtonPropsExcept<SubmitButtonProps, 'onSubmit' | 'disabled' | 'loading'>—Submit button customization — applied to the default footer, and to defaults.submitButton when renderActions is provided
resetButtonPropsExcept<ResetButtonProps, 'onReset' | 'disabled' | 'loading'> | false—Reset button customization; false hides it — applied to the default footer, and to defaults.resetButton when renderActions is provided (which false leaves empty)
childrenReactNode | (formApi) => ReactNode—Form content
// Add a custom button alongside the defaults
renderActions={(formApi, { submitButton, resetButton }) => (
<>
<Button onClick={handleDraft}>Save Draft</Button>
{resetButton}
{submitButton}
</>
)}