cx 24.5.2 → 24.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data.js +1 -1
- package/dist/manifest.js +771 -771
- package/dist/svg.js +1 -5
- package/dist/ui.js +2 -3
- package/dist/widgets.js +20 -11
- package/package.json +1 -1
- package/src/widgets/form/Field.js +446 -441
- package/src/widgets/form/LookupField.js +1135 -1130
|
@@ -1,441 +1,446 @@
|
|
|
1
|
-
import { VDOM, getContent } from "../../ui/Widget";
|
|
2
|
-
import { PureContainer } from "../../ui/PureContainer";
|
|
3
|
-
import { ValidationError } from "./ValidationError";
|
|
4
|
-
import { HelpText } from "./HelpText";
|
|
5
|
-
import { Label } from "./Label";
|
|
6
|
-
import { stopPropagation } from "../../util/eventCallbacks";
|
|
7
|
-
import { isSelector } from "../../data/isSelector";
|
|
8
|
-
import { Localization } from "../../ui/Localization";
|
|
9
|
-
import { isPromise } from "../../util/isPromise";
|
|
10
|
-
import { Console } from "../../util/Console";
|
|
11
|
-
import { parseStyle } from "../../util/parseStyle";
|
|
12
|
-
import { FocusManager } from "../../ui/FocusManager";
|
|
13
|
-
import { isTouchEvent } from "../../util/isTouchEvent";
|
|
14
|
-
import { tooltipMouseLeave, tooltipMouseMove } from "../overlay/tooltip-ops";
|
|
15
|
-
import { coalesce } from "../../util/coalesce";
|
|
16
|
-
import { isUndefined } from "../../util/isUndefined";
|
|
17
|
-
import { shallowEquals } from "../../util/shallowEquals";
|
|
18
|
-
import { FieldIcon } from "./FieldIcon";
|
|
19
|
-
|
|
20
|
-
export class Field extends PureContainer {
|
|
21
|
-
declareData() {
|
|
22
|
-
super.declareData(
|
|
23
|
-
{
|
|
24
|
-
label: undefined,
|
|
25
|
-
labelWidth: undefined,
|
|
26
|
-
mode: undefined,
|
|
27
|
-
viewMode: undefined,
|
|
28
|
-
id: undefined,
|
|
29
|
-
error: undefined,
|
|
30
|
-
inputStyle: { structured: true },
|
|
31
|
-
inputClass: { structured: true },
|
|
32
|
-
inputAttrs: { structured: true },
|
|
33
|
-
emptyText: undefined,
|
|
34
|
-
visited: undefined,
|
|
35
|
-
autoFocus: undefined,
|
|
36
|
-
tabOnEnterKey: undefined,
|
|
37
|
-
tabIndex: undefined,
|
|
38
|
-
validationParams: { structured: true },
|
|
39
|
-
},
|
|
40
|
-
...arguments,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
init() {
|
|
45
|
-
this.inputStyle = parseStyle(this.inputStyle);
|
|
46
|
-
super.init();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
initComponents(context, instance) {
|
|
50
|
-
if (this.validationMode == "tooltip" && isUndefined(this.errorTooltip)) {
|
|
51
|
-
this.errorTooltip = {
|
|
52
|
-
text: { bind: "$error" },
|
|
53
|
-
mod: "error",
|
|
54
|
-
...this.errorTooltip,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (isUndefined(this.help)) {
|
|
59
|
-
switch (this.validationMode) {
|
|
60
|
-
case "help":
|
|
61
|
-
case "help-inline":
|
|
62
|
-
this.help = ValidationError;
|
|
63
|
-
break;
|
|
64
|
-
|
|
65
|
-
case "help-block":
|
|
66
|
-
this.help = {
|
|
67
|
-
type: ValidationError,
|
|
68
|
-
mod: "block",
|
|
69
|
-
};
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (this.help != null) {
|
|
75
|
-
let helpConfig = {};
|
|
76
|
-
|
|
77
|
-
if (this.help.isComponentType) helpConfig = this.help;
|
|
78
|
-
else if (isSelector(this.help)) helpConfig.text = this.help;
|
|
79
|
-
else Object.assign(helpConfig, this.help);
|
|
80
|
-
|
|
81
|
-
this.help = HelpText.create(helpConfig);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (this.label != null) {
|
|
85
|
-
let labelConfig = {
|
|
86
|
-
mod: this.mod,
|
|
87
|
-
disabled: this.disabled,
|
|
88
|
-
required: this.required,
|
|
89
|
-
asterisk: this.asterisk,
|
|
90
|
-
style: this.labelStyle,
|
|
91
|
-
class: this.labelClass,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
if (this.label.isComponentType) labelConfig = this.label;
|
|
95
|
-
else if (isSelector(this.label)) labelConfig.text = this.label;
|
|
96
|
-
else Object.assign(labelConfig, this.label);
|
|
97
|
-
|
|
98
|
-
this.label = Label.create(labelConfig);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (this.icon != null) {
|
|
102
|
-
let iconConfig = {
|
|
103
|
-
className: this.CSS.element(this.baseClass, "icon"),
|
|
104
|
-
};
|
|
105
|
-
if (isSelector(this.icon)) iconConfig.name = this.icon;
|
|
106
|
-
else Object.assign(iconConfig, this.icon);
|
|
107
|
-
|
|
108
|
-
this.icon = FieldIcon.create(iconConfig);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return super.initComponents(...arguments, {
|
|
112
|
-
label: this.label,
|
|
113
|
-
help: this.help,
|
|
114
|
-
icon: this.icon,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
initState(context, instance) {
|
|
119
|
-
instance.state = {
|
|
120
|
-
inputError: false,
|
|
121
|
-
visited: this.visited === true,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
prepareData(context, instance) {
|
|
126
|
-
let { data, state } = instance;
|
|
127
|
-
if (!data.id) data.id = "fld-" + instance.id;
|
|
128
|
-
|
|
129
|
-
data._disabled = data.disabled;
|
|
130
|
-
data._readOnly = data.readOnly;
|
|
131
|
-
data._viewMode = data.mode === "view" || data.viewMode;
|
|
132
|
-
data._tabOnEnterKey = data.tabOnEnterKey;
|
|
133
|
-
|
|
134
|
-
instance.
|
|
135
|
-
instance.
|
|
136
|
-
instance.
|
|
137
|
-
instance.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
"
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
instance.
|
|
201
|
-
instance.
|
|
202
|
-
instance.
|
|
203
|
-
instance.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
instance.cache("
|
|
208
|
-
instance.cache("
|
|
209
|
-
instance.cache("
|
|
210
|
-
instance.cache("
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
data.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
let
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
{
|
|
366
|
-
{
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
Field.prototype.
|
|
411
|
-
Field.prototype.
|
|
412
|
-
Field.prototype.
|
|
413
|
-
Field.prototype.
|
|
414
|
-
Field.prototype.
|
|
415
|
-
Field.prototype.
|
|
416
|
-
Field.prototype.
|
|
417
|
-
Field.prototype.
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
1
|
+
import { VDOM, getContent } from "../../ui/Widget";
|
|
2
|
+
import { PureContainer } from "../../ui/PureContainer";
|
|
3
|
+
import { ValidationError } from "./ValidationError";
|
|
4
|
+
import { HelpText } from "./HelpText";
|
|
5
|
+
import { Label } from "./Label";
|
|
6
|
+
import { stopPropagation } from "../../util/eventCallbacks";
|
|
7
|
+
import { isSelector } from "../../data/isSelector";
|
|
8
|
+
import { Localization } from "../../ui/Localization";
|
|
9
|
+
import { isPromise } from "../../util/isPromise";
|
|
10
|
+
import { Console } from "../../util/Console";
|
|
11
|
+
import { parseStyle } from "../../util/parseStyle";
|
|
12
|
+
import { FocusManager } from "../../ui/FocusManager";
|
|
13
|
+
import { isTouchEvent } from "../../util/isTouchEvent";
|
|
14
|
+
import { tooltipMouseLeave, tooltipMouseMove } from "../overlay/tooltip-ops";
|
|
15
|
+
import { coalesce } from "../../util/coalesce";
|
|
16
|
+
import { isUndefined } from "../../util/isUndefined";
|
|
17
|
+
import { shallowEquals } from "../../util/shallowEquals";
|
|
18
|
+
import { FieldIcon } from "./FieldIcon";
|
|
19
|
+
|
|
20
|
+
export class Field extends PureContainer {
|
|
21
|
+
declareData() {
|
|
22
|
+
super.declareData(
|
|
23
|
+
{
|
|
24
|
+
label: undefined,
|
|
25
|
+
labelWidth: undefined,
|
|
26
|
+
mode: undefined,
|
|
27
|
+
viewMode: undefined,
|
|
28
|
+
id: undefined,
|
|
29
|
+
error: undefined,
|
|
30
|
+
inputStyle: { structured: true },
|
|
31
|
+
inputClass: { structured: true },
|
|
32
|
+
inputAttrs: { structured: true },
|
|
33
|
+
emptyText: undefined,
|
|
34
|
+
visited: undefined,
|
|
35
|
+
autoFocus: undefined,
|
|
36
|
+
tabOnEnterKey: undefined,
|
|
37
|
+
tabIndex: undefined,
|
|
38
|
+
validationParams: { structured: true },
|
|
39
|
+
},
|
|
40
|
+
...arguments,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
init() {
|
|
45
|
+
this.inputStyle = parseStyle(this.inputStyle);
|
|
46
|
+
super.init();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
initComponents(context, instance) {
|
|
50
|
+
if (this.validationMode == "tooltip" && isUndefined(this.errorTooltip)) {
|
|
51
|
+
this.errorTooltip = {
|
|
52
|
+
text: { bind: "$error" },
|
|
53
|
+
mod: "error",
|
|
54
|
+
...this.errorTooltip,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isUndefined(this.help)) {
|
|
59
|
+
switch (this.validationMode) {
|
|
60
|
+
case "help":
|
|
61
|
+
case "help-inline":
|
|
62
|
+
this.help = ValidationError;
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
case "help-block":
|
|
66
|
+
this.help = {
|
|
67
|
+
type: ValidationError,
|
|
68
|
+
mod: "block",
|
|
69
|
+
};
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (this.help != null) {
|
|
75
|
+
let helpConfig = {};
|
|
76
|
+
|
|
77
|
+
if (this.help.isComponentType) helpConfig = this.help;
|
|
78
|
+
else if (isSelector(this.help)) helpConfig.text = this.help;
|
|
79
|
+
else Object.assign(helpConfig, this.help);
|
|
80
|
+
|
|
81
|
+
this.help = HelpText.create(helpConfig);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.label != null) {
|
|
85
|
+
let labelConfig = {
|
|
86
|
+
mod: this.mod,
|
|
87
|
+
disabled: this.disabled,
|
|
88
|
+
required: this.required,
|
|
89
|
+
asterisk: this.asterisk,
|
|
90
|
+
style: this.labelStyle,
|
|
91
|
+
class: this.labelClass,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (this.label.isComponentType) labelConfig = this.label;
|
|
95
|
+
else if (isSelector(this.label)) labelConfig.text = this.label;
|
|
96
|
+
else Object.assign(labelConfig, this.label);
|
|
97
|
+
|
|
98
|
+
this.label = Label.create(labelConfig);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (this.icon != null) {
|
|
102
|
+
let iconConfig = {
|
|
103
|
+
className: this.CSS.element(this.baseClass, "icon"),
|
|
104
|
+
};
|
|
105
|
+
if (isSelector(this.icon)) iconConfig.name = this.icon;
|
|
106
|
+
else Object.assign(iconConfig, this.icon);
|
|
107
|
+
|
|
108
|
+
this.icon = FieldIcon.create(iconConfig);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return super.initComponents(...arguments, {
|
|
112
|
+
label: this.label,
|
|
113
|
+
help: this.help,
|
|
114
|
+
icon: this.icon,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
initState(context, instance) {
|
|
119
|
+
instance.state = {
|
|
120
|
+
inputError: false,
|
|
121
|
+
visited: this.visited === true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
prepareData(context, instance) {
|
|
126
|
+
let { data, state } = instance;
|
|
127
|
+
if (!data.id) data.id = "fld-" + instance.id;
|
|
128
|
+
|
|
129
|
+
data._disabled = data.disabled;
|
|
130
|
+
data._readOnly = data.readOnly;
|
|
131
|
+
data._viewMode = data.mode === "view" || data.viewMode;
|
|
132
|
+
data._tabOnEnterKey = data.tabOnEnterKey;
|
|
133
|
+
data.validationValue = this.getValidationValue(data);
|
|
134
|
+
instance.parentDisabled = context.parentDisabled;
|
|
135
|
+
instance.parentReadOnly = context.parentReadOnly;
|
|
136
|
+
instance.parentViewMode = context.parentViewMode;
|
|
137
|
+
instance.parentTabOnEnterKey = context.parentTabOnEnterKey;
|
|
138
|
+
instance.parentVisited = context.parentVisited;
|
|
139
|
+
|
|
140
|
+
if (typeof data.enabled !== "undefined") data._disabled = !data.enabled;
|
|
141
|
+
|
|
142
|
+
this.disableOrValidate(context, instance);
|
|
143
|
+
|
|
144
|
+
data.inputStyle = parseStyle(data.inputStyle);
|
|
145
|
+
|
|
146
|
+
if (this.labelPlacement && this.label) data.mod = [data.mod, "label-placement-" + this.labelPlacement];
|
|
147
|
+
|
|
148
|
+
if (this.helpPlacement && this.help) data.mod = [data.mod, "help-placement-" + this.helpPlacement];
|
|
149
|
+
|
|
150
|
+
data.empty = this.isEmpty(data);
|
|
151
|
+
|
|
152
|
+
super.prepareData(...arguments);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
disableOrValidate(context, instance) {
|
|
156
|
+
let { data, state } = instance;
|
|
157
|
+
|
|
158
|
+
//if the parent is strict and sets some flag to true, it is not allowed to overrule that flag by field settings
|
|
159
|
+
|
|
160
|
+
data.disabled = coalesce(
|
|
161
|
+
context.parentStrict ? context.parentDisabled : null,
|
|
162
|
+
data._disabled,
|
|
163
|
+
context.parentDisabled,
|
|
164
|
+
);
|
|
165
|
+
data.readOnly = coalesce(
|
|
166
|
+
context.parentStrict ? context.parentReadOnly : null,
|
|
167
|
+
data._readOnly,
|
|
168
|
+
context.parentReadOnly,
|
|
169
|
+
);
|
|
170
|
+
data.viewMode = coalesce(
|
|
171
|
+
context.parentStrict ? context.parentViewMode : null,
|
|
172
|
+
data._viewMode,
|
|
173
|
+
context.parentViewMode,
|
|
174
|
+
);
|
|
175
|
+
data.tabOnEnterKey = coalesce(
|
|
176
|
+
context.parentStrict ? context.parentTabOnEnterKey : null,
|
|
177
|
+
data._tabOnEnterKey,
|
|
178
|
+
context.parentTabOnEnterKey,
|
|
179
|
+
);
|
|
180
|
+
data.visited = coalesce(context.parentStrict ? context.parentVisited : null, data.visited, context.parentVisited);
|
|
181
|
+
|
|
182
|
+
if (!data.error && !data.disabled && !data.viewMode) this.validate(context, instance);
|
|
183
|
+
|
|
184
|
+
if (data.visited && !state.visited) {
|
|
185
|
+
//feels hacky but it should be ok since we're in the middle of a new render cycle
|
|
186
|
+
state.visited = true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
data.stateMods = {
|
|
190
|
+
...data.stateMods,
|
|
191
|
+
disabled: data.disabled,
|
|
192
|
+
"edit-mode": !data.viewMode,
|
|
193
|
+
"view-mode": data.viewMode,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
explore(context, instance) {
|
|
198
|
+
let { data, state } = instance;
|
|
199
|
+
|
|
200
|
+
instance.parentDisabled = context.parentDisabled;
|
|
201
|
+
instance.parentReadOnly = context.parentReadOnly;
|
|
202
|
+
instance.parentViewMode = context.parentViewMode;
|
|
203
|
+
instance.parentTabOnEnterKey = context.parentTabOnEnterKey;
|
|
204
|
+
instance.parentVisited = context.parentVisited;
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
instance.cache("parentDisabled", context.parentDisabled) ||
|
|
208
|
+
instance.cache("parentReadOnly", context.parentReadOnly) ||
|
|
209
|
+
instance.cache("parentViewMode", context.parentViewMode) ||
|
|
210
|
+
instance.cache("parentTabOnEnterKey", context.parentTabOnEnterKey) ||
|
|
211
|
+
instance.cache("parentVisited", context.parentVisited)
|
|
212
|
+
) {
|
|
213
|
+
instance.markShouldUpdate(context);
|
|
214
|
+
this.disableOrValidate(context, instance);
|
|
215
|
+
this.prepareCSS(context, instance);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!context.validation)
|
|
219
|
+
context.validation = {
|
|
220
|
+
errors: [],
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
if (data.error) {
|
|
224
|
+
context.validation.errors.push({
|
|
225
|
+
fieldId: data.id,
|
|
226
|
+
message: data.error,
|
|
227
|
+
visited: state.visited,
|
|
228
|
+
type: "error",
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
context.push("lastFieldId", data.id);
|
|
233
|
+
super.explore(context, instance);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
exploreCleanup(context, instance) {
|
|
237
|
+
context.pop("lastFieldId");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
isEmpty(data) {
|
|
241
|
+
return data.value == null || data.value === this.emptyValue;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
validateRequired(context, instance) {
|
|
245
|
+
let { data } = instance;
|
|
246
|
+
if (this.isEmpty(data)) return this.requiredText;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
getValidationValue(data) {
|
|
250
|
+
return data.value;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
validate(context, instance) {
|
|
254
|
+
let { data, state } = instance;
|
|
255
|
+
state = state || {};
|
|
256
|
+
|
|
257
|
+
let empty = this.isEmpty(data);
|
|
258
|
+
|
|
259
|
+
if (!data.error) {
|
|
260
|
+
if (state.inputError) data.error = state.inputError;
|
|
261
|
+
else if (state.validating && !empty) data.error = this.validatingText;
|
|
262
|
+
else if (
|
|
263
|
+
state.validationError &&
|
|
264
|
+
data.validationValue === state.lastValidatedValue &&
|
|
265
|
+
shallowEquals(data.validationParams, state.lastValidationParams)
|
|
266
|
+
)
|
|
267
|
+
data.error = state.validationError;
|
|
268
|
+
else if (data.required) data.error = this.validateRequired(context, instance);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (
|
|
272
|
+
!empty &&
|
|
273
|
+
!state.validating &&
|
|
274
|
+
!data.error &&
|
|
275
|
+
this.onValidate &&
|
|
276
|
+
(!state.previouslyValidated ||
|
|
277
|
+
data.validationValue != state.lastValidatedValue ||
|
|
278
|
+
data.validationParams != state.lastValidationParams)
|
|
279
|
+
) {
|
|
280
|
+
let result = instance.invoke("onValidate", data.validationValue, instance, data.validationParams);
|
|
281
|
+
if (isPromise(result)) {
|
|
282
|
+
data.error = this.validatingText;
|
|
283
|
+
instance.setState({
|
|
284
|
+
validating: true,
|
|
285
|
+
lastValidatedValue: data.validationValue,
|
|
286
|
+
previouslyValidated: true,
|
|
287
|
+
lastValidationParams: data.validationParams,
|
|
288
|
+
});
|
|
289
|
+
result
|
|
290
|
+
.then((r) => {
|
|
291
|
+
let { data, state } = instance;
|
|
292
|
+
let error =
|
|
293
|
+
data.validationValue == state.lastValidatedValue &&
|
|
294
|
+
shallowEquals(data.validationParams, state.lastValidationParams)
|
|
295
|
+
? r
|
|
296
|
+
: this.validatingText; //parameters changed, this will be revalidated
|
|
297
|
+
|
|
298
|
+
instance.setState({
|
|
299
|
+
validating: false,
|
|
300
|
+
validationError: error,
|
|
301
|
+
});
|
|
302
|
+
})
|
|
303
|
+
.catch((e) => {
|
|
304
|
+
instance.setState({
|
|
305
|
+
validating: false,
|
|
306
|
+
validationError: this.validationExceptionText,
|
|
307
|
+
});
|
|
308
|
+
if (this.onValidationException) instance.invoke("onValidationException", e, instance);
|
|
309
|
+
else {
|
|
310
|
+
Console.warn("Unhandled validation exception:", e);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
data.error = result;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
renderLabel(context, instance, key) {
|
|
320
|
+
if (instance.components.label) return getContent(instance.components.label.vdom);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
renderInput(context, instance, key) {
|
|
324
|
+
throw new Error("Not implemented.");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
renderHelp(context, instance, key) {
|
|
328
|
+
if (instance.components.help) return getContent(instance.components.help.render(context, key));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
renderIcon(context, instance, key) {
|
|
332
|
+
if (instance.components.icon) return getContent(instance.components.icon.render(context, key));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
formatValue(context, { data }) {
|
|
336
|
+
return data.text || data.value;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
renderValue(context, instance, key) {
|
|
340
|
+
let text = this.formatValue(context, instance);
|
|
341
|
+
if (text) {
|
|
342
|
+
return (
|
|
343
|
+
<span
|
|
344
|
+
key={key}
|
|
345
|
+
onMouseMove={(e) => tooltipMouseMove(e, ...getFieldTooltip(instance))}
|
|
346
|
+
onMouseLeave={(e) => tooltipMouseLeave(e, ...getFieldTooltip(instance))}
|
|
347
|
+
>
|
|
348
|
+
{text}
|
|
349
|
+
</span>
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
renderContent(context, instance, key) {
|
|
355
|
+
let content = this.renderValue(...arguments) || this.renderEmptyText(...arguments);
|
|
356
|
+
return this.renderWrap(context, instance, key, content);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
renderWrap(context, instance, key, content) {
|
|
360
|
+
let { data } = instance;
|
|
361
|
+
let interactive = !data.viewMode && !data.disabled;
|
|
362
|
+
return (
|
|
363
|
+
<div
|
|
364
|
+
key={key}
|
|
365
|
+
className={data.classNames}
|
|
366
|
+
style={data.style}
|
|
367
|
+
onMouseDown={interactive ? stopPropagation : null}
|
|
368
|
+
onTouchStart={interactive ? stopPropagation : null}
|
|
369
|
+
>
|
|
370
|
+
{content}
|
|
371
|
+
{this.labelPlacement && this.renderLabel(context, instance, "label")}
|
|
372
|
+
</div>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
renderEmptyText(context, { data }, key) {
|
|
377
|
+
return (
|
|
378
|
+
<span key={key} className={this.CSS.element(this.baseClass, "empty-text")}>
|
|
379
|
+
{data.emptyText || <span> </span>}
|
|
380
|
+
</span>
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
render(context, instance, key) {
|
|
385
|
+
let { data } = instance;
|
|
386
|
+
let content = !data.viewMode
|
|
387
|
+
? this.renderInput(context, instance, key)
|
|
388
|
+
: this.renderContent(context, instance, key);
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
label: !this.labelPlacement && this.renderLabel(context, instance, key),
|
|
392
|
+
content: content,
|
|
393
|
+
helpSpacer: this.helpSpacer && instance.components.help ? " " : null,
|
|
394
|
+
help: !this.helpPlacement && this.renderHelp(context, instance, key),
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
handleKeyDown(e, instance) {
|
|
399
|
+
if (this.onKeyDown && instance.invoke("onKeyDown", e, instance) === false) return false;
|
|
400
|
+
|
|
401
|
+
if (instance.data.tabOnEnterKey && e.keyCode === 13) {
|
|
402
|
+
let target = e.target;
|
|
403
|
+
setTimeout(() => {
|
|
404
|
+
if (!instance.state.inputError) FocusManager.focusNext(target);
|
|
405
|
+
}, 10);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
Field.prototype.validationMode = "tooltip";
|
|
411
|
+
Field.prototype.suppressErrorsUntilVisited = false;
|
|
412
|
+
Field.prototype.requiredText = "This field is required.";
|
|
413
|
+
Field.prototype.autoFocus = false;
|
|
414
|
+
Field.prototype.asterisk = false;
|
|
415
|
+
Field.prototype.validatingText = "Validation is in progress...";
|
|
416
|
+
Field.prototype.validationExceptionText = "Something went wrong during input validation. Check log for more details.";
|
|
417
|
+
Field.prototype.helpSpacer = true;
|
|
418
|
+
Field.prototype.trackFocus = false; //add cxs-focus on parent element
|
|
419
|
+
Field.prototype.labelPlacement = false;
|
|
420
|
+
Field.prototype.helpPlacement = false;
|
|
421
|
+
Field.prototype.emptyValue = null;
|
|
422
|
+
Field.prototype.styled = true;
|
|
423
|
+
|
|
424
|
+
//These flags are inheritable and should not be set to false
|
|
425
|
+
//Field.prototype.visited = null;
|
|
426
|
+
//Field.prototype.disabled = null;
|
|
427
|
+
//Field.prototype.readOnly = null;
|
|
428
|
+
//Field.prototype.viewMode = null;
|
|
429
|
+
|
|
430
|
+
Localization.registerPrototype("cx/widgets/Field", Field);
|
|
431
|
+
|
|
432
|
+
export function getFieldTooltip(instance) {
|
|
433
|
+
let { widget, data, state } = instance;
|
|
434
|
+
|
|
435
|
+
if (widget.errorTooltip && data.error && (!state || state.visited || !widget.suppressErrorsUntilVisited))
|
|
436
|
+
return [
|
|
437
|
+
instance,
|
|
438
|
+
widget.errorTooltip,
|
|
439
|
+
{
|
|
440
|
+
data: {
|
|
441
|
+
$error: data.error,
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
];
|
|
445
|
+
return [instance, widget.tooltip];
|
|
446
|
+
}
|