Skip to content

Commit c0827a9

Browse files
authored
Merge branch 'main' into fix/wildcard_issue_in_routes
2 parents 32357ec + 516c7b9 commit c0827a9

31 files changed

+830
-133
lines changed

.ai/inertia-laravel/2/core.blade.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@
1111

1212
### Deferred Props & Empty States
1313
- When using deferred props on the frontend, you should add a nice empty state with pulsing / animated skeleton.
14+
15+
### Inertia Form General Guidance
16+
@if ($assist->inertia()->hasFormComponent())
17+
- The recommended way to build forms when using Inertia is with the `<Form>` component - a useful example is below. Use `search-docs` with a query of `form component` for guidance.
18+
- Forms can also be built using the `useForm` helper for more programmatic control, or to follow existing conventions. Use `search-docs` with a query of `useForm helper` for guidance.
19+
@if ($assist->inertia()->hasFormComponentResets())
20+
- `resetOnError`, `resetOnSuccess`, and `setDefaultsOnSuccess` are available on the `<Form>` component. Use `search-docs` with a query of 'form component resetting' for guidance.
21+
@else
22+
- This version of Inertia does not support `resetOnError`, `resetOnSuccess`, or `setDefaultsOnSuccess` on the `<Form>` component. Using these will cause errors.
23+
@endif
24+
@else
25+
- Build forms using the `useForm` helper. Use the code examples and `search-docs` tool with a query of `useForm helper` for guidance.
26+
@endif

.ai/inertia-laravel/core.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Inertia.js components should be placed in the `resources/js/Pages` directory unless specified differently in the JS bundler (vite.config.js).
44
- Use `Inertia::render()` for server-side routing instead of traditional Blade views.
5+
- Use `search-docs` for accurate guidance on all things Inertia.
56

67
<code-snippet lang="php" name="Inertia::render Example">
78
// routes/web.php example

.ai/inertia-react/1/.gitkeep

Whitespace-only changes.

.ai/inertia-react/1/forms.blade.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Inertia + React Forms
2+
3+
- For form handling in Inertia pages, use `router.post` and related methods. Do not use regular forms.
4+
5+
@verbatim
6+
<code-snippet name="Inertia React Form Example" lang="react">
7+
import { useState } from 'react'
8+
import { router } from '@inertiajs/react'
9+
10+
export default function Edit() {
11+
const [values, setValues] = useState({
12+
first_name: "",
13+
last_name: "",
14+
email: "",
15+
})
16+
17+
function handleChange(e) {
18+
const key = e.target.id;
19+
const value = e.target.value
20+
21+
setValues(values => ({
22+
...values,
23+
[key]: value,
24+
}))
25+
}
26+
27+
function handleSubmit(e) {
28+
e.preventDefault()
29+
30+
router.post('/users', values)
31+
}
32+
33+
return (
34+
<form onSubmit={handleSubmit}>
35+
<label htmlFor="first_name">First name:</label>
36+
<input id="first_name" value={values.first_name} onChange={handleChange} />
37+
<label htmlFor="last_name">Last name:</label>
38+
<input id="last_name" value={values.last_name} onChange={handleChange} />
39+
<label htmlFor="email">Email:</label>
40+
<input id="email" value={values.email} onChange={handleChange} />
41+
<button type="submit">Submit</button>
42+
</form>
43+
)
44+
}
45+
</code-snippet>
46+
@endverbatim

.ai/inertia-react/2/.gitkeep

Whitespace-only changes.

.ai/inertia-react/2/forms.blade.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@php
2+
/** @var \Laravel\Boost\Install\GuidelineAssist $assist */
3+
@endphp
4+
## Inertia + React Forms
5+
6+
@if($assist->inertia()->hasFormComponent())
7+
@boostsnippet("`<Form>` Component Example", "react")
8+
import { Form } from '@inertiajs/react'
9+
10+
export default () => (
11+
<Form action="/users" method="post">
12+
{({
13+
errors,
14+
hasErrors,
15+
processing,
16+
wasSuccessful,
17+
recentlySuccessful,
18+
clearErrors,
19+
resetAndClearErrors,
20+
defaults
21+
}) => (
22+
<>
23+
<input type="text" name="name" />
24+
25+
{errors.name && <div>{errors.name}</div>}
26+
27+
<button type="submit" disabled={processing}>
28+
{processing ? 'Creating...' : 'Create User'}
29+
</button>
30+
31+
{wasSuccessful && <div>User created successfully!</div>}
32+
</>
33+
)}
34+
</Form>
35+
)
36+
@endboostsnippet
37+
@endif
38+
39+
@if($assist->inertia()->hasFormComponent() === false)
40+
{{-- Inertia 2.0.x, not 2.1.0 or higher. So they still need to use 'useForm' --}}
41+
@boostsnippet("Inertia React useForm Example", "react")
42+
import { useForm } from '@inertiajs/react'
43+
44+
const { data, setData, post, processing, errors } = useForm({
45+
email: '',
46+
password: '',
47+
remember: false,
48+
})
49+
50+
function submit(e) {
51+
e.preventDefault()
52+
post('/login')
53+
}
54+
55+
return (
56+
<form onSubmit={submit}>
57+
<input type="text" value={data.email} onChange={e => setData('email', e.target.value)} />
58+
{errors.email && <div>{errors.email}</div>}
59+
<input type="password" value={data.password} onChange={e => setData('password', e.target.value)} />
60+
{errors.password && <div>{errors.password}</div>}
61+
<input type="checkbox" checked={data.remember} onChange={e => setData('remember', e.target.checked)} /> Remember Me
62+
<button type="submit" disabled={processing}>Login</button>
63+
</form>
64+
)
65+
@endboostsnippet
66+
@endif

.ai/inertia-react/core.blade.php

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,7 @@
22

33
- Use `router.visit()` or `<Link>` for navigation instead of traditional links.
44

5-
<code-snippet lang="react" name="Inertia Client Navigation">
6-
import { Link } from '@inertiajs/react'
7-
8-
<Link href="/">Home</Link>
9-
</code-snippet>
10-
11-
- For form handling, use `router.post` and related methods. Do not use regular forms.
12-
13-
<code-snippet lang="react" name="Inertia React Form Example">
14-
import { useState } from 'react'
15-
import { router } from '@inertiajs/react'
16-
17-
export default function Edit() {
18-
const [values, setValues] = useState({
19-
first_name: "",
20-
last_name: "",
21-
email: "",
22-
})
23-
24-
function handleChange(e) {
25-
const key = e.target.id;
26-
const value = e.target.value
27-
28-
setValues(values => ({
29-
...values,
30-
[key]: value,
31-
}))
32-
}
33-
34-
function handleSubmit(e) {
35-
e.preventDefault()
36-
37-
router.post('/users', values)
38-
}
39-
40-
return (
41-
<form onSubmit={handleSubmit}>
42-
<label htmlFor="first_name">First name:</label>
43-
<input id="first_name" value={values.first_name} onChange={handleChange} />
44-
<label htmlFor="last_name">Last name:</label>
45-
<input id="last_name" value={values.last_name} onChange={handleChange} />
46-
<label htmlFor="email">Email:</label>
47-
<input id="email" value={values.email} onChange={handleChange} />
48-
<button type="submit">Submit</button>
49-
</form>
50-
)
51-
}
52-
</code-snippet>
5+
@boostsnippet("Inertia Client Navigation", "react")
6+
import { Link } from '@inertiajs/react'
7+
<Link href="/">Home</Link>
8+
@endboostsnippet

.ai/inertia-svelte/1/forms.blade.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Inertia + Svelte Forms
2+
3+
- For form handling, use `router.post` and related methods. Do not use regular forms.
4+
5+
@verbatim
6+
<code-snippet lang="svelte" name="Inertia Form Example">
7+
<script>
8+
import { router } from '@inertiajs/svelte'
9+
10+
let values = {
11+
first_name: null,
12+
last_name: null,
13+
email: null,
14+
}
15+
16+
function handleSubmit() {
17+
router.post('/users', values)
18+
}
19+
</script>
20+
21+
<form on:submit|preventDefault={handleSubmit}>
22+
<label for="first_name">First name:</label>
23+
<input id="first_name" bind:value={values.first_name}>
24+
25+
<label for="last_name">Last name:</label>
26+
<input id="last_name" bind:value={values.last_name}>
27+
28+
<label for="email">Email:</label>
29+
<input id="email" bind:value={values.email}>
30+
31+
<button type="submit">Submit</button>
32+
</form>
33+
</code-snippet>
34+
@endverbatim

.ai/inertia-svelte/2/forms.blade.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
@php
2+
/** @var \Laravel\Boost\Install\GuidelineAssist $assist */
3+
@endphp
4+
## Inertia + Svelte Forms
5+
6+
- There are critical differences between Svelte 4 and 5, use the `search-docs` tool for up-to-date guidance.
7+
8+
@if($assist->inertia()->hasFormComponent())
9+
@boostsnippet("`<Form>` Component Example", "svelte5")
10+
<Form action="/users" method="post">
11+
{#snippet children({
12+
errors,
13+
hasErrors,
14+
processing,
15+
progress,
16+
wasSuccessful,
17+
recentlySuccessful,
18+
setError,
19+
clearErrors,
20+
resetAndClearErrors,
21+
defaults,
22+
isDirty,
23+
reset,
24+
submit,
25+
})}
26+
<input type="text" name="name" />
27+
28+
{#if errors.name}
29+
<div>{errors.name}</div>
30+
{/if}
31+
32+
<button type="submit" disabled={processing}>
33+
{processing ? 'Creating...' : 'Create User'}
34+
</button>
35+
36+
{#if wasSuccessful}
37+
<div>User created successfully!</div>
38+
{/if}
39+
{/snippet}
40+
</Form>
41+
@endboostsnippet
42+
@endif
43+
44+
@if($assist->inertia()->hasFormComponent() === false)
45+
{{-- Inertia 2.0.x, not 2.1.0 or higher. So they still need to use 'useForm' --}}
46+
@boostsnippet("Inertia Svelte useForm Example", "svelte")
47+
<script>
48+
import { useForm } from '@inertiajs/svelte'
49+
50+
const form = useForm({
51+
email: null,
52+
password: null,
53+
remember: false,
54+
})
55+
56+
function submit(e) {
57+
e.preventDefault() /* Only required with Svelte 5 */
58+
$form.post('/login')
59+
}
60+
</script>
61+
62+
<form onsubmit={submit}>
63+
<input type="text" bind:value={$form.email} />
64+
{#if $form.errors.email}
65+
<div class="form-error">{$form.errors.email}</div>
66+
{/if}
67+
<input type="password" bind:value={$form.password} />
68+
{#if $form.errors.password}
69+
<div class="form-error">{$form.errors.password}</div>
70+
{/if}
71+
<input type="checkbox" bind:checked={$form.remember} /> Remember Me
72+
<button type="submit" disabled={$form.processing}>Submit</button>
73+
</form>
74+
@endboostsnippet
75+
@endif

.ai/inertia-svelte/core.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Inertia + Svelte
2+
3+
- Use `router.visit()` or `<Link>` for navigation instead of traditional links.
4+
5+
@boostsnippet("Inertia Client Navigation", "svelte")
6+
import { inertia, Link } from '@inertiajs/svelte'
7+
8+
<a href="/" use:inertia>Home</a>
9+
<Link href="/">Home</Link>
10+
@endboostsnippet

0 commit comments

Comments
 (0)