X Enterprises
nuxt-x-app-formkit

Modal

FormKit-powered modal form with automatic CRUD mode and legacy submit support.

Modal

XFormModal wraps a FormKit form inside a UModal. In CRUD mode (pass an endpoint prop) the component fetches an existing record by recordId, runs FormKit validation on submit, posts/puts to the API, shows a toast, and optionally refreshes or navigates on success. In legacy mode (omit endpoint) handle submission yourself via the @submit event.

Components

<XFormModal />

<!-- CRUD mode — create -->
<XFormModal v-model="open" endpoint="/api/users" on-success="refresh">
  <FormKitText name="name" label="Name" validation="required" />
  <FormKitText name="email" label="Email" validation="required|email" />
</XFormModal>

<!-- CRUD mode — edit -->
<XFormModal v-model="open" endpoint="/api/users" :record-id="user.id" on-success="refresh" />

<!-- Legacy mode -->
<XFormModal v-model="open" title="Custom Form" @submit="handleSubmit">
  <input v-model="form.name" />
</XFormModal>

Props

PropTypeDefaultDescription
modelValuebooleanfalseControls modal open state (v-model)
titlestring""Modal header title. Auto-derived from endpoint when omitted
size"sm" | "md" | "lg" | "xl" | "full""md"Max-width of the modal content
closablebooleantrueShow the X close button in the header
loadingbooleanfalseExternal loading state merged into button disabled/spinner
disabledbooleanfalseDisable the submit button
submitTextstring"Save"Submit button label (auto becomes "Create" / "Update" in CRUD mode)
cancelTextstring"Cancel"Cancel button label
confirmClosebooleanfalseSuppress auto-close on X click; handle @close yourself
endpointstringAPI base path (e.g. /api/users). Enables CRUD mode
recordIdstring | numberID of the record to fetch and edit
initialDataRecord<string, any>Pre-populate form without fetching from API
method"POST" | "PUT" | "PATCH"autoHTTP method override (defaults to POST for create, PUT for edit)
idKeystring"id"Key used to detect and append record ID to the URL
headersRecord<string,string> | () => Record<string,string>Extra request headers, or a function returning them
transform(data) => dataTransform form data before it is sent to the API
showToastbooleantrueShow success/error toasts via useToast()
closeOnSuccessbooleantrueClose modal after a successful API call
resetOnClosebooleantrueClear form data when the modal closes
formIdstringautoOverride the generated FormKit form node ID
onSuccess"refresh" | "navigate" | FunctionPost-success action: refresh Nuxt data, navigate to a route, or custom callback
navigateTostringRoute template for onSuccess: "navigate" (supports :id / {id})

Emits

EventPayloadDescription
update:modelValuebooleanv-model sync
submitFired in legacy mode when the submit button is clicked
closeFired when the X or Cancel button is clicked
success(data, response)Fired after a successful API call
error(error)Fired when the API call fails
loaded(data)Fired after the record is fetched by recordId

Exposed Methods

MethodDescription
open(data?)Open the modal and optionally pre-populate form data
close()Close the modal
reset()Re-initialize form data
submit()Programmatically trigger form submission

AI Context

component: XFormModal
package: "@xenterprises/nuxt-x-app-formkit"
crud-mode: pass endpoint prop; component handles fetch/submit/toast/close automatically
legacy-mode: omit endpoint; handle @submit event yourself
success-behaviors: onSuccess="refresh" | "navigate" | custom function
form-engine: FormKit (validation, node.submit(), node.setErrors())
ui-primitive: UModal (Nuxt UI)
use-when: Modal forms for creating or editing a resource via API
Copyright © 2026