-
Notifications
You must be signed in to change notification settings - Fork 2
/
FieldStore.ts
103 lines (85 loc) · 2.75 KB
/
FieldStore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Binding } from '../binder/Binder'
export interface FieldStore<ValueType> {
/**
* The `name` is typically used for the `input` field name.
*/
readonly name: string
/**
* The "type" of the value. For `string`, the Binder has some special handling like Converting empty strings to `undefined` and vice versa.
*/
readonly valueType: string
/**
* Indicates if the values has changed since last `Binder.load()` or `Binder.setUnchanged()`
* This property is replaced by a getter on bind.
*/
readonly changed: boolean
/**
* If false, validation results should not be shown - like on initial rendering or until first field blur event.
*/
showValidationResults: boolean
/**
* The current value of the form field.
*/
value: ValueType
/**
* The validity status of a form field. Always set, except for unfinished async validations.
* This property is replaced by a getter on bind.
*/
readonly valid?: boolean
/**
* Set to `true` when a field gets focus for the first time.
*/
visited: boolean
/**
* Set to `true` on first change. Fields are untouched initially, after load() or reset()
*/
readonly touched: boolean
/**
* `true` when an async validation is in progress for the current field.
* This property is replaced by a getter on bind.
*/
readonly validating: boolean
/**
* If `valid === false`, containing the validation message.
* This property is bound to .
*/
errorMessage?: string
/**
* Indicates if the field is read only.
*/
readOnly: boolean
/**
* Indicates if the field is a mandatory field.
* This property is replaced by a getter on bind.
*/
required: boolean
/**
* Optionally return an object with field state rendered into the Binding.state for debugging purposes.
*/
readonly debugState?: unknown
/**
* This function must be used to update field values via the frontend.
*
* @param newValue
*/
updateValue(newValue: ValueType): void
/**
* This must be called on blur events for proper validation handling. Implementation has to set `showValidationResults` to `true`.
*/
handleBlur(): void
/**
* This should be called on focus events for proper `visited` status. Implementation has to set `visited` to `true`.
*/
handleFocus(): void
/**
* This is called by the binder framework on load and resets most of the fields to initial status.
*
* @param newValue
*/
reset(newValue: ValueType): void
/**
* This is used internally to bind a field
* @param binding
*/
bind(binding: Binding<unknown, unknown>): void
}