diff --git a/docs/guide/events.md b/docs/guide/events.md index 8ce9f962..699f0f9b 100644 --- a/docs/guide/events.md +++ b/docs/guide/events.md @@ -228,7 +228,7 @@ document.removeEventListener('inertia:start', startEventListener) ## Cancelling events -Some events, such as `before`, `invalid`, and `error`, support cancellation, allowing you to prevent Inertia's default behavior. Just like native events, the event will be cancelled if only one event listener calls `event.preventDefault()`. +Some events, such as `before`, `exception`, and `invalid`, support cancellation, allowing you to prevent Inertia's default behavior. Just like native events, the event will be cancelled if only one event listener calls `event.preventDefault()`. :::tabs key:frameworks == Vue diff --git a/docs/guide/forms.md b/docs/guide/forms.md index 3f7d4d3d..ffaabd6a 100644 --- a/docs/guide/forms.md +++ b/docs/guide/forms.md @@ -1,194 +1,943 @@ # Forms -## Submitting forms +Inertia provides two primary ways to build forms: the `
` component and the `useForm` helper. Both integrate with your server-side framework's validation and handle form submissions without full page reloads. + +## Form component + +@available_since core=2.1.0 + +Inertia provides a `` component that behaves much like a classic HTML form, but uses Inertia under the hood to avoid full page reloads. This is the simplest way to get started with forms in Inertia: + +### Submitting forms While it's possible to make classic HTML form submissions with Inertia, it's not recommended since they cause full-page reloads. Instead, it's better to intercept form submissions and then make the [request using Inertia](/guide/manual-visits.md). :::tabs key:frameworks + == Vue ```vue -const form = reactive({ - first_name: null, - last_name: null, - email: null, -}) + +``` -function submit() { - router.post('/users', form) -} +Just like a traditional HTML form, there is no need to attach a `v-model` to your input fields, just give each input a `name` attribute and the `Form` component will handle the data submission for you. + +== React + +```jsx +import { Form } from '@inertiajs/react' + +export default () => ( + + + + +
+) +``` + +Just like a traditional HTML form, there is no need to attach an `onChange` handler to your input fields, just give each input a `name` attribute and a `defaultValue` (if applicable) and the `Form` component will handle the data submission for you. + +== Svelte 4 | Svelte 5 + +```svelte + -