CoreActionForm Component
TheCoreActionForm component extends CoreForm to provide seamless integration with CoreAction backend operations. It automatically handles action execution, validation error display, loading states, and confirmation dialogs.
Related Documentation:
- See Core Form Documentation for base form functionality
- See Core Actions Documentation for action creation and backend patterns
Overview
CoreActionForm wraps CoreForm and adds action-specific functionality:
- Automatic Action Execution - Executes
CoreActionon form submission - Parameter Merging - Combines form data with
params/getParamsfollowing priority rules - Validation Error Handling - Automatically displays backend validation errors on form fields
- Loading States - Manages loading state from
useCoreActionhook - Confirmation Dialogs - Shows confirmation prompts for actions marked with
confirm: true - Model Binding - Supports automatic Eloquent model resolution from IDs
Basic Usage
Controlled Mode (Recommended)
Uncontrolled Mode
Props
CoreActionForm extends all CoreForm props and adds action-specific props:
Action-Specific Props
action:CoreActionData(required) - The action to execute on form submissionparams?:Record<string, any>- Static parameters to merge with form datagetParams?:() => Record<string, any>- Dynamic parameter function computed at execution timeonSuccess?:() => void- Success callback fired when action completes successfullyonError?:(error: any) => void- Error callback fired for non-validation errorsonValidationError?:(errors: any) => void- Validation error callback (errors are also automatically displayed on fields)
Inherited CoreForm Props
AllCoreForm props are available:
form?: Inertia form object (for controlled mode)footer?: ReactNode to render in the form footerdisabled?: Boolean to disable all form fieldsclassName?: Additional CSS classes for the form layoutchildren: ReactNode or function that receives form props
How Action Submission Works
- User submits form → Form data is collected from all form fields
- Parameters are merged → Form data is automatically merged with
params/getParams(if provided) - Confirmation check → If action has
confirm: true, shows confirmation dialog - Action executes →
useCoreActionhook executes the action with merged parameters - Validation → Backend validates parameters using action’s
rules()method - Error Display → Validation errors automatically appear on corresponding form fields
- Success/Error → Callbacks are fired based on result
Parameter Merging
Form data is always included. Parameters follow this priority order (highest to lowest):getParams()- Dynamic params computed at execution time (overrides form data)paramsprop - Static params passed to component (overrides form data)- Form data - Values from form fields
- Backend defaults - Default params from action’s
params()method
Dynamic Parameters with getParams
UsegetParams to include data not in the form or transform form data:
Overriding Parameters
Useparams prop to add parameters that aren’t in the form:
Validation Error Handling
Validation errors from action rules are automatically displayed on form fields: Backend Action:onValidationError callback is also fired, allowing you to handle errors programmatically:
Success/Error Callbacks
Model Binding
Actions automatically resolve Eloquent models from IDs. Pass model IDs in form data or viagetParams:
Confirmation Dialogs
Actions marked withconfirm: true automatically show a confirmation dialog before execution:
Backend Action:
- Shows the action’s
labelas the title - Shows
confirmMessage(or default message) as description - Uses the action’s
variantfor the confirm button - Prevents form submission until confirmed
Action vs Regular Form Submission
| Feature | Regular Form (onSubmit/action URL) | Action Form (CoreActionForm) |
|---|---|---|
| Submission | Manual handler or URL | Automatic action execution |
| Validation | Manual error handling | Automatic from action rules |
| Loading State | Manual processing state | Automatic from useCoreAction |
| Parameters | Form data only | Form data + action params |
| Backend | Generic routes | CoreAction system |
| Confirmation | Manual implementation | Automatic for confirm: true |
Complete Example
Backend Action:Best Practices
- Use Controlled Mode - Prefer controlled mode with
useFormhook for better type safety and programmatic control - Leverage getParams - Use
getParamsfor dynamic data that changes at execution time - Use params for Static Data - Use
paramsprop for static data that doesn’t change - Handle Errors Gracefully - Use
onErrorandonValidationErrorcallbacks for custom error handling - Model Binding - Pass model IDs and let the backend resolve models automatically
- Confirmation Dialogs - Use
confirm: trueon actions that are destructive or irreversible - Type Safety - Use TypeScript to ensure form data matches action parameter types
See Also
- Core Form Documentation - Base form functionality
- Core Actions Documentation - Backend action patterns
- Form Field Components - Available form field components