You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-19Lines changed: 21 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,9 @@ import { decode } from 'https://deno.land/x/decode_formdata/mod.ts';
31
31
32
32
`FormData` stores the names of your fields and their values. However, there is a problem. Only strings and files are accepted as values, but complex forms can contain booleans, strings and dates. This leads to the fact that the boolean value `true` must be mapped with `"on"` and `false` values are simply ignored. Numbers and dates are also converted to strings.
33
33
34
-
Another problem are objects and arrays, which are usually mapped using dot notation. For example, the input field `<input name="todos.0.label" />` should map to the object `{ todos: [{ label: "" }] }`. By telling `decode` where arrays, booleans, dates, files, and numbers are located, the function can decode your `FormData` back into a complex JavaScript object.
34
+
Another problem are objects and arrays, which are usually mapped using dot and bracket notation. For example, the input field `<input name="todos.0.label" />` should map to the object `{ todos: [{ label: "" }] }`. By telling `decode` where arrays, booleans, dates, files, and numbers are located, the function can decode your `FormData` back into a complex JavaScript object.
35
+
36
+
> Both dot and bracket notation are supported for arrays.
35
37
36
38
Consider the following form to add a new product to an online store:
37
39
@@ -46,17 +48,17 @@ Consider the following form to add a new product to an online store:
46
48
<inputname="active"type="checkbox" />
47
49
48
50
<!-- Tags -->
49
-
<inputname="tags[0]"type="text" />
50
-
<inputname="tags[1]"type="text" />
51
-
<inputname="tags[2]"type="text" />
51
+
<inputname="tags.0"type="text" />
52
+
<inputname="tags.1"type="text" />
53
+
<inputname="tags.2"type="text" />
52
54
53
55
<!-- Images -->
54
-
<inputname="images[0].title"type="text" />
55
-
<inputname="images[0].created"type="date" />
56
-
<inputname="images[0].file"type="file" />
57
-
<inputname="images[1].title"type="text" />
58
-
<inputname="images[1].created"type="date" />
59
-
<inputname="images[1].file"type="file" />
56
+
<inputname="images.0.title"type="text" />
57
+
<inputname="images.0.created"type="date" />
58
+
<inputname="images.0.file"type="file" />
59
+
<inputname="images.1.title"type="text" />
60
+
<inputname="images.1.created"type="date" />
61
+
<inputname="images.1.file"type="file" />
60
62
</form>
61
63
```
62
64
@@ -68,15 +70,15 @@ const formEntries = [
68
70
['price', '0.89'],
69
71
['created', '2023-10-09'],
70
72
['active', 'on'],
71
-
['tags[0]', 'fruit'],
72
-
['tags[1]', 'healthy'],
73
-
['tags[2]', 'sweet'],
74
-
['images[0].title', 'Close up of an apple'],
75
-
['images[0].created', '2023-08-24'],
76
-
['images[0].file', Blob],
77
-
['images[1].title', 'Our fruit fields at Lake Constance'],
78
-
['images[1].created', '2023-08-12'],
79
-
['images[1].file', Blob],
73
+
['tags.0', 'fruit'],
74
+
['tags.1', 'healthy'],
75
+
['tags.2', 'sweet'],
76
+
['images.0.title', 'Close up of an apple'],
77
+
['images.0.created', '2023-08-24'],
78
+
['images.0.file', Blob],
79
+
['images.1.title', 'Our fruit fields at Lake Constance'],
0 commit comments