How It Works β
Lifecycle β
VueForm manages the complete CRUD lifecycle automatically based on the mode (create or update). Understanding this flow helps you configure the plugin correctly.
Modes β
<VueForm> operates in one of two modes: Create or Update. The mode is automatically determined based on whether an item ID is present.
1. Create Mode β
When you're creating a new item and don't have an existing ID.
- No initial data is fetched from the API
- Form fields are populated with default values from your field configuration
- The
<VueFormCreate>button is visible - Clicking the button calls your
createmethod to save the new item
2. Update Mode β
When you're editing an existing item and have a unique ID from the database.
- The read method is called with the item ID to fetch existing data
- Form fields are pre-filled with the retrieved data
- The
<VueFormUpdate>button is visible - Clicking the button calls your
updatemethod to save changes
To configure the mode detection, use the isNewItemCheck option. Read more
On Mount & Read β
When <VueForm> mounts, the following sequence occurs:
- Mode Detection: VueForm calls
isNewItemCheckwith theitem-idprop to determine the operation mode. - Create Mode: when
isNewItemCheckreturnstrue- No API call is made
- Default field values are applied from the field configuration
- Update Mode: when
isNewItemCheckreturnsfalse- The
readfunction is called withitemIdas the argument - You fetch the existing data from the API and return it
- Populates form fields with the retrieved data
- The
Create β
The <VueFormCreate> renders a create button. The button is only visible in create mode.
When clicked:
- VueForm calls the
createmethod from props - The create method performs the API call and returns the result
- On success: Form state updates with the new response data
- On failure: The
errorAdaptoris called to format and display errors
Update β
The <VueFormUpdate> renders an update button. The button is only visible in update mode.
When clicked:
- VueForm calls the
updatemethod from props - The update method performs the API call and returns the result
- On success: Form state updates with the new response data
- On failure: The
errorAdaptoris called to format and display errors