Skip to content

useTableForms ​

Manages the create/edit form panel inside a data table — open/close state, loading, errors, and the custom-form-modal workflow.

File: vue/src/js/hooks/table/useTableForms.js


Props Factory ​

js
import { makeTableFormsProps } from '@/hooks/table/useTableForms'
PropTypeDefaultDescription
inputFieldsArray[]Legacy override for the form's field list
formSchemaObjectrequiredSchema definition for the table's create/edit form
formWidthString|Number'60%'Width of the form modal
createOnModalBooleantrueOpen the create form in a modal
editOnModalBooleantrueOpen the edit form in a modal
embeddedFormBooleanfalseEmbed the form inline instead of in a modal
addBtnOptionsObject{}Props for the "Add" button (e.g. custom text)
noFormBooleanfalseDisable create/edit form entirely
formActionsArray|Object[]Extra action buttons in the form footer

Usage ​

js
import useTableForms, { makeTableFormsProps } from '@/hooks/table/useTableForms'

const {
  formActive,
  UeForm,
  formLoading,
  formErrors,
  addBtnTitle,
  openForm,
  closeForm,
  createForm,
  handleFormSubmission,
} = useTableForms(props, context)

Returns ​

State ​

NameTypeDescription
formActiveRef<Boolean>Whether the create/edit form is visible
UeFormRefTemplate ref to the <UeForm> component
customFormModalActiveRef<Boolean>Whether the custom action-form modal is open
customFormSchemaRef<Object>Schema for the custom action form
customFormModelRef<Object>Model for the custom action form
customFormAttributesRef<Object>Attributes for the custom action form
customFormModalAttributesRef<Object>Modal attributes for the custom action form

Computed ​

NameTypeDescription
formRefComputedRef<String>Unique DOM ref name for the form
formStylesComputedRef<Object>{ width: formWidth } style object
formLoadingComputedRef<Boolean>true while the form is submitting
formErrorsComputedRef<Object>Current validation errors from the Vuex form store
formIsValidComputedRef<Boolean|null>Form validity state from UeForm
addBtnTitleComputedRef<String>Translated "Add {item}" label for the create button

Methods ​

NameSignatureDescription
openForm() => voidOpen the create/edit form
closeForm() => voidClose the form and reset the edited item
createForm() => voidReset the edited item to defaults and open the form
handleFormSubmission(data) => voidCalled on form submit response — closes form and reloads table on success

Notes ​

  • Closing the form automatically calls resetEditedItem() via a watcher on formActive.
  • handleFormSubmission checks data.variant === 'success' before triggering a reload.

See Also ​