@@ -1012,7 +1012,7 @@ export default function () {
1012
1012
offers a declarative approach to form handling. At its simplest, the component behaves much like a classic HTML
1013
1013
form, but with all the benefits of Inertia's SPA-like navigation. While < Code > useForm()</ Code > gives you programmatic
1014
1014
control over form data and submission logic, the < Code > <Form></ Code > component is ideal when you prefer a
1015
- more HTML-like, declarative approach with minimal JavaScript .
1015
+ more HTML-like, declarative approach.
1016
1016
</ P >
1017
1017
< TabbedCode
1018
1018
examples = { [
@@ -1292,6 +1292,64 @@ export default function () {
1292
1292
} ,
1293
1293
] }
1294
1294
/>
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
+ />
1295
1353
< H3 > Props and options</ H3 >
1296
1354
< P >
1297
1355
In addition to < Code > action</ Code > and < Code > method</ Code > , the < Code > <Form></ Code > component accepts
@@ -1391,8 +1449,8 @@ export default function () {
1391
1449
</ P >
1392
1450
< H3 > Events</ H3 >
1393
1451
< P >
1394
- The < Code > <Form></ Code > component emits the same events as < Code > useForm() </ Code > , except
1395
- the ones related to prefetching :
1452
+ The < Code > <Form></ 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 :
1396
1454
</ P >
1397
1455
< TabbedCode
1398
1456
examples = { [
@@ -1485,7 +1543,7 @@ export default function () {
1485
1543
< H3 > Dotted key notation</ H3 >
1486
1544
< P >
1487
1545
The < Code > <Form></ 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.
1489
1547
</ P >
1490
1548
< TabbedCode
1491
1549
examples = { [
@@ -1609,80 +1667,6 @@ export default function () {
1609
1667
} ,
1610
1668
] }
1611
1669
/>
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
- />
1686
1670
< H2 > File uploads</ H2 >
1687
1671
< P >
1688
1672
When making requests or form submissions that include files, Inertia will automatically convert the request data
0 commit comments