Complete Form Lifecycle
A form that only handles creation is half a form. The full lifecycle of a record — from first save to final deletion — involves multiple operations that need to be handled consistently: initial creation, subsequent edits, validation at every save, and eventual deletion. Each of these operations has failure cases, edge cases, and feedback requirements.
Swifty's form component handles the complete lifecycle without any additional wiring.
Creation Mode
When no record ID is present in the context, the form operates in creation mode. Fields start empty (or with configured defaults). Submitting the form creates a new record with the entered values. After successful creation, the form navigates to the new record's detail view, or to a configured destination.
If validation fails, errors appear inline next to each failing field. The form stays open. The user corrects the errors and resubmits. No data is lost between failed submission attempts — field values are preserved.
Edit Mode
When a record ID is present, the form loads that record's data and enters edit mode. All fields are pre-populated with current values. Saving updates the record. The form shows a last-saved timestamp so users know when the record was last changed.
Edit mode supports dirty-state tracking — the form knows whether any values have changed since loading. Navigating away with unsaved changes triggers a confirmation prompt. No accidental data loss.
Validation
Validation runs on every save attempt. Required fields are checked. Format constraints are enforced (dates must be valid dates, numbers must be in the allowed range). Option fields must contain one of the defined options. Custom cross-field validation rules run after individual field validation.
Validation errors are displayed per field, as close to the relevant input as possible. A summary at the top of the form lists all errors for cases where the relevant field has scrolled off screen.
Delete
Delete is a first-class operation in the form lifecycle, not an afterthought. A delete button (configured per form) triggers a confirmation dialog explaining what will be deleted. Confirming removes the record and navigates away from the now-empty form — typically to the list that contained the record.
Delete permissions follow the same role rules as all other operations. If the current user doesn't have delete access, the delete button simply doesn't appear.
Consistent Everywhere
Every form in the application uses the same lifecycle component. A form on a standalone page, a form in a modal, a form in a sidebar panel — all handle creation, editing, validation, and deletion consistently. Users develop one mental model for how forms work and apply it everywhere.