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: articles/hilla/lit/guides/forms/reference.adoc
+24-19
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ description: Understanding form binding.
9
9
10
10
// tag::content[]
11
11
12
-
The key concepts behind form binding are: the [methodname]`field()` directive, the [classname]`Model`, the [classname]`Binder` and binder nodes.
12
+
The key concepts behind form binding are the [methodname]`field()` directive, the [classname]`Model`, the [classname]`Binder` and binder nodes.
13
13
14
14
15
15
== The Field Directive
@@ -18,15 +18,15 @@ ifdef::hilla-lit[]
18
18
Form binding in Hilla works together with the Lit web component library and its underlying template rendering library, `lit-html`.
19
19
endif::hilla-lit[]
20
20
21
-
The [methodname]`field()` directive does the main task of binding the form field components in the template:
21
+
The [methodname]`field()` directive does the main task of binding the form field components in the template by doing the following:
22
22
23
23
- sets the `name` attribute;
24
24
- implements two-way binding for the value state;
25
25
- sets the `required` (boolean) state; and
26
26
- sets the `invalid` (boolean) state and the `errorMessage` (string) when the current value is invalid.
27
27
28
28
ifdef::hilla-react[]
29
-
.Using the field directive
29
+
.Using the Field Directive
30
30
[source,tsx]
31
31
----
32
32
import {TextField} from "@vaadin/react-components/TextField.js";
@@ -38,8 +38,9 @@ return (
38
38
);
39
39
----
40
40
endif::hilla-react[]
41
+
41
42
ifdef::hilla-lit[]
42
-
.Using the field directive
43
+
.Using the Field Directive
43
44
[source,html]
44
45
----
45
46
<vaadin-text-field
@@ -53,10 +54,10 @@ Depending on the type of the bound component, the field directive selects a stra
53
54
54
55
ifdef::hilla-lit[]
55
56
[NOTE]
56
-
You can find more information on field strategy customization in the <<{articles}/hilla/lit/guides/forms/web-component-field-strategy#, Using a Web Component Field>> article.
57
+
You can find more information on field strategy customization on the <<{articles}/hilla/lit/guides/forms/web-component-field-strategy#, Using a Web Component Field>> page.
57
58
endif::hilla-lit[]
58
59
59
-
The field directive supports Vaadin components and HTML input elements. Vaadin components have support for all the states. However, for HTML input elements, the `invalid`, `required` and `errorMessage` states aren't displayed in the bound component. As a workaround, you can bind these manually in the template:
60
+
The field directive supports Vaadin components and HTML input elements. Vaadin components have support for all of the states. However, for HTML input elements, the `invalid`, `required` and `errorMessage` states aren't displayed in the bound component. As a workaround, you can manually bind these in the template:
60
61
61
62
ifdef::hilla-react[]
62
63
[source,tsx]
@@ -114,8 +115,8 @@ ${
114
115
----
115
116
endif::hilla-lit[]
116
117
117
-
[NOTE]
118
-
See also: <<{articles}/hilla/lit/guides/forms/vaadin-components#, Binding Data to Hilla Components>>
118
+
See the <<{articles}/hilla/lit/guides/forms/vaadin-components#, Binding Data to Hilla Components>> for more, related information.
119
+
119
120
120
121
121
122
== The Form Model
@@ -130,27 +131,25 @@ to specify the target form property to create a binding or to access the state.
130
131
131
132
Hilla automatically generates Model classes for server-side endpoints from Java beans. There's usually no need to define models, manually.
132
133
133
-
Technically, every model instance represents either a key of a parent model, or the value of the [classname]`Binder` itself (for example, the form data object).
134
+
Technically, every model instance represents either a key of a parent model, or the value of the [classname]`Binder` itself (e.g., the form data object).
134
135
135
136
[NOTE]
136
-
====
137
137
The model classes aren't intended to be instantiated manually. Instead, the [classname]`Binder` constructor receives the form model class and takes care of creating model instances.
138
-
====
139
138
140
139
141
140
=== Primitive Models
142
141
143
142
These are the built-in models that represent the common primitive field types:
144
143
145
144
|===
146
-
| Type | Value type `T` | Empty value ([methodname]`Model.createEmptyValue()` result)
145
+
| Type | Value type `T` | Empty Value ([methodname]`Model.createEmptyValue()` result)
147
146
148
147
| [classname]`StringModel` | `string` | `''`
149
148
| [classname]`NumberModel` | `number` | `0`
150
149
| [classname]`BooleanModel` | `boolean` | `false`
151
150
|===
152
151
153
-
Primitive models extend [classname]`PrimitiveModel<T>`. Primitive models are leaf nodes of the data structure; that is, they don't have nested field keys.
152
+
Primitive models extend [classname]`PrimitiveModel<T>`. Primitive models are leaf nodes of the data structure; they don't have nested field keys.
154
153
155
154
156
155
=== Object Models
@@ -243,13 +242,12 @@ export default class PersonModel<T extends Person = Person> extends IdEntityMode
243
242
----
244
243
245
244
[CAUTION]
246
-
====
247
245
To avoid naming collisions with user-defined object model fields, the built-in models and model superclasses don't have any public instance properties or methods, aside from the [methodname]`toString()` and [methodname]`valueOf()` methods inherited from [classname]`AbstractModel<T>` (see following).
248
-
====
249
246
250
247
The properties of object models are intentionally read-only.
251
248
252
-
=== The Array Model
249
+
250
+
=== Array Model
253
251
254
252
[classname]`ArrayModel<T>` is used to represent array properties.
255
253
@@ -306,12 +304,12 @@ endif::hilla-lit[]
306
304
The array entries aren't available for indexing with bracket notation (`[]`).
307
305
308
306
309
-
=== The Abstract Model Superclass
307
+
=== Abstract Model Superclass
310
308
311
309
All models subclass from the [classname]`AbstractModel<T>` TypeScript class, where the `T` type argument refers to the value type.
312
310
313
311
314
-
==== The Empty Value Definition
312
+
==== Empty Value Definition
315
313
316
314
Model classes define an empty value, which is used to initialize the `defaultValue` and `value` properties, and also for [methodname]`clear()`.
317
315
@@ -350,7 +348,7 @@ return (
350
348
)
351
349
----
352
350
353
-
Then, it is possible to use the values in formulas using either of the followings:
351
+
Then, it's possible to use the values in formulas using either of the following:
354
352
355
353
[source,tsx]
356
354
----
@@ -432,6 +430,7 @@ Sets the form to empty value, as defined in the Model.
432
430
Determines and returns the `field` directive strategy for the bound element. Override to customize the binding strategy for a component. The [classname]`Binder` extends [classname]`BinderNode`; see the inherited properties and methods that follow.
433
431
434
432
433
+
435
434
== Binder Nodes [[binder-node]]
436
435
437
436
The [classname]`BinderNode<T, M>` class provides the form-binding-related APIs with respect to a particular model instance.
@@ -490,3 +489,9 @@ A helper method for array modes, similar to [methodname]`appendItem()`, but prep
490
489
A helper method for array item models. If the node's **parent model** is an [classname]`ArrayModel<T>`, removes the item the array; otherwise throws an exception.
0 commit comments