Skip to content

Commit 04e64a2

Browse files
committed
wip
1 parent 2d6d24d commit 04e64a2

File tree

1 file changed

+62
-78
lines changed

1 file changed

+62
-78
lines changed

resources/js/Pages/forms.jsx

Lines changed: 62 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ export default function () {
10121012
offers a declarative approach to form handling. At its simplest, the component behaves much like a classic HTML
10131013
form, but with all the benefits of Inertia's SPA-like navigation. While <Code>useForm()</Code> gives you programmatic
10141014
control over form data and submission logic, the <Code>&lt;Form&gt;</Code> component is ideal when you prefer a
1015-
more HTML-like, declarative approach with minimal JavaScript.
1015+
more HTML-like, declarative approach.
10161016
</P>
10171017
<TabbedCode
10181018
examples={[
@@ -1292,6 +1292,64 @@ export default function () {
12921292
},
12931293
]}
12941294
/>
1295+
<P>
1296+
The <Code>errors</Code> object uses dotted notation for nested fields, allowing you to display validation
1297+
messages for complex form structures:
1298+
</P>
1299+
<TabbedCode
1300+
examples={[
1301+
{
1302+
name: 'Vue',
1303+
language: 'markup',
1304+
code: dedent`
1305+
<Form action="/users" method="post" #default="{ errors }">
1306+
<input type="text" name="user.name" />
1307+
<div v-if="errors['user.name']">{{ errors['user.name'] }}</div>
1308+
</Form>
1309+
`,
1310+
},
1311+
{
1312+
name: 'React',
1313+
language: 'jsx',
1314+
code: dedent`
1315+
<Form action="/users" method="post">
1316+
{({ errors }) => (
1317+
<>
1318+
<input type="text" name="user.name" />
1319+
{errors['user.name'] && <div>{errors['user.name']}</div>}
1320+
</>
1321+
)}
1322+
</Form>
1323+
`,
1324+
},
1325+
{
1326+
name: 'Svelte 4',
1327+
language: 'html',
1328+
code: dedent`
1329+
<Form action="/users" method="post" let:errors>
1330+
<input type="text" name="user.name" />
1331+
{#if errors['user.name']}
1332+
<div>{errors['user.name']}</div>
1333+
{/if}
1334+
</Form>
1335+
`,
1336+
},
1337+
{
1338+
name: 'Svelte 5',
1339+
language: 'html',
1340+
code: dedent`
1341+
<Form action="/users" method="post">
1342+
{#snippet children({ errors })}
1343+
<input type="text" name="user.name" />
1344+
{#if errors['user.name']}
1345+
<div>{errors['user.name']}</div>
1346+
{/if}
1347+
{/snippet}
1348+
</Form>
1349+
`,
1350+
},
1351+
]}
1352+
/>
12951353
<H3>Props and options</H3>
12961354
<P>
12971355
In addition to <Code>action</Code> and <Code>method</Code>, the <Code>&lt;Form&gt;</Code> component accepts
@@ -1391,8 +1449,8 @@ export default function () {
13911449
</P>
13921450
<H3>Events</H3>
13931451
<P>
1394-
The <Code>&lt;Form&gt;</Code> component emits the same events as <Code>useForm()</Code>, except
1395-
the ones related to prefetching:
1452+
The <Code>&lt;Form&gt;</Code> component emits all the standard visit <A href="/events">events</A> for form
1453+
submissions, plus a <Code>cancelToken</Code> event for handling form cancellation:
13961454
</P>
13971455
<TabbedCode
13981456
examples={[
@@ -1485,7 +1543,7 @@ export default function () {
14851543
<H3>Dotted key notation</H3>
14861544
<P>
14871545
The <Code>&lt;Form&gt;</Code> component supports dotted key notation for creating nested objects from flat
1488-
input names. This provides a convenient way to structure form data without needing complex JavaScript logic.
1546+
input names. This provides a convenient way to structure form data.
14891547
</P>
14901548
<TabbedCode
14911549
examples={[
@@ -1609,80 +1667,6 @@ export default function () {
16091667
},
16101668
]}
16111669
/>
1612-
<P>
1613-
When using dotted keys or arrays, validation errors follow the same structure. You can access errors for
1614-
specific array indices or nested fields:
1615-
</P>
1616-
<TabbedCode
1617-
examples={[
1618-
{
1619-
name: 'Vue',
1620-
language: 'markup',
1621-
code: dedent`
1622-
<Form action="/users" method="post" #default="{ errors }">
1623-
<input type="text" name="tags[]" />
1624-
<div v-if="errors['tags.0']">{{ errors['tags.0'] }}</div>
1625-
1626-
<input type="text" name="user.name" />
1627-
<div v-if="errors['user.name']">{{ errors['user.name'] }}</div>
1628-
</Form>
1629-
`,
1630-
},
1631-
{
1632-
name: 'React',
1633-
language: 'jsx',
1634-
code: dedent`
1635-
<Form action="/users" method="post">
1636-
{({ errors }) => (
1637-
<>
1638-
<input type="text" name="tags[]" />
1639-
{errors['tags.0'] && <div>{errors['tags.0']}</div>}
1640-
1641-
<input type="text" name="user.name" />
1642-
{errors['user.name'] && <div>{errors['user.name']}</div>}
1643-
</>
1644-
)}
1645-
</Form>
1646-
`,
1647-
},
1648-
{
1649-
name: 'Svelte 4',
1650-
language: 'html',
1651-
code: dedent`
1652-
<Form action="/users" method="post" let:errors>
1653-
<input type="text" name="tags[]" />
1654-
{#if errors['tags.0']}
1655-
<div>{errors['tags.0']}</div>
1656-
{/if}
1657-
1658-
<input type="text" name="user.name" />
1659-
{#if errors['user.name']}
1660-
<div>{errors['user.name']}</div>
1661-
{/if}
1662-
</Form>
1663-
`,
1664-
},
1665-
{
1666-
name: 'Svelte 5',
1667-
language: 'html',
1668-
code: dedent`
1669-
<Form action="/users" method="post">
1670-
{#snippet children({ errors })}
1671-
<input type="text" name="tags[]" />
1672-
{#if errors['tags.0']}
1673-
<div>{errors['tags.0']}</div>
1674-
{/if}
1675-
1676-
<input type="text" name="user.name" />
1677-
{#if errors['user.name']}
1678-
<div>{errors['user.name']}</div>
1679-
{/if}
1680-
{/snippet}
1681-
</Form>
1682-
`,
1683-
},
1684-
]}
1685-
/>
16861670
<H2>File uploads</H2>
16871671
<P>
16881672
When making requests or form submissions that include files, Inertia will automatically convert the request data

0 commit comments

Comments
 (0)