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: docs/03-code-internals/21-form-kit.md
+27-8Lines changed: 27 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1039,8 +1039,11 @@ The object component allows to handle an object in your form.
1039
1039
1040
1040
```hbs
1041
1041
<Form @data={{hash foo=(hash bar=1 baz=2)}} as |form|>
1042
-
<form.Object @name="foo" as |object name|>
1043
-
<object.Field @name={{name}} @title={{name}} as |field|>
1042
+
<form.Object @name="foo" as |object data|>
1043
+
<object.Field @name="bar" @title="Bar" as |field|>
1044
+
<field.Input />
1045
+
</object.Field>
1046
+
<object.Field @name="baz" @title="Baz" as |field|>
1044
1047
<field.Input />
1045
1048
</object.Field>
1046
1049
</form.Object>
@@ -1054,7 +1057,7 @@ An object must have a unique name. This name is used as a prefix for the underly
1054
1057
**Example**
1055
1058
1056
1059
```hbs
1057
-
<form.Collection @name="foo" />
1060
+
<form.Object @name="foo" />
1058
1061
```
1059
1062
1060
1063
## Nesting
@@ -1066,18 +1069,18 @@ An object can accept a nested Object or Collection.
1066
1069
```hbs
1067
1070
<Form @data={{hash foo=(hash bar=(hash baz=1 bol=2))}} as |form|>
1068
1071
<form.Object @name="foo" as |parentObject|>
1069
-
<parentObject.Object @name="bar" as |childObject name|>
1070
-
<childObject.Field @name={{name}} @title={{name}} as |field|>
1072
+
<parentObject.Object @name="bar" as |childObject data|>
1073
+
<childObject.Field @name="baz" @title="Baz" as |field|>
1071
1074
<field.Input />
1072
1075
</childObject.Field>
1073
1076
</parentObject.Object>
1074
1077
</form.Object>
1075
1078
</Form>
1076
1079
1077
-
<Form @data={{hash foo=(hash bar=(array (hash baz=1) (hash baz=2)))}} as |form|>
1080
+
<Form @data={{hash foo=(hash bar=(array 1 2))}} as |form|>
1078
1081
<form.Object @name="foo" as |parentObject|>
1079
1082
<parentObject.Collection @name="bar" as |collection index|>
1080
-
<collection.Field @name="baz" @title="baz" as |field|>
1083
+
<collection.Field @title="Baz" as |field|>
1081
1084
<field.Input />
1082
1085
</collection.Field>
1083
1086
<form.Button
@@ -1119,14 +1122,30 @@ For example, if collection has the name "foo", the 2nd field of the collection w
1119
1122
1120
1123
## @tagName
1121
1124
1122
-
A collection will by default render as a `<div class="form-kit__collection>`, you can alter this behavior by setting a `@tagName`.
1125
+
A collection will by default render as a `<div class="form-kit__collection>`, you can alter this behavior by using a `@tagName`.
1123
1126
1124
1127
**Example**
1125
1128
1126
1129
```hbs
1127
1130
<form.Collection @name="foo" @tagName="tr" />
1128
1131
```
1129
1132
1133
+
## Primitive array
1134
+
1135
+
If the shape of your data is an array of primitives, eg: [1, 2, 3], form-kit is able to handle it. You just have to omit the name on the field in this case, as the name will be auto generated for you with the index.
1136
+
1137
+
**Example**
1138
+
1139
+
```hbs
1140
+
<Form @data={{hash foo=(array 1 2)}} as |form|>
1141
+
<form.Collection @name="foo" as |collection|>
1142
+
<collection.Field @title="Baz" as |field|>
1143
+
<field.Input />
1144
+
</collection.Field>
1145
+
</form.Object>
1146
+
</Form>
1147
+
```
1148
+
1130
1149
## Nesting
1131
1150
1132
1151
A collection can accept a nested Object or Collection.
0 commit comments