cx 26.2.2 → 26.2.3

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.
Files changed (324) hide show
  1. package/build/charts/Chart.d.ts.map +1 -1
  2. package/build/charts/Chart.js +5 -4
  3. package/build/charts/ColumnBarBase.d.ts +3 -3
  4. package/build/charts/ColumnBarBase.d.ts.map +1 -1
  5. package/build/charts/ColumnBarBase.js +1 -1
  6. package/build/charts/Legend.d.ts.map +1 -1
  7. package/build/charts/Legend.js +11 -4
  8. package/build/charts/Marker.d.ts +3 -3
  9. package/build/charts/Marker.d.ts.map +1 -1
  10. package/build/charts/MarkerLine.d.ts +7 -7
  11. package/build/charts/MarkerLine.d.ts.map +1 -1
  12. package/build/charts/MarkerLine.js +14 -10
  13. package/build/charts/PieChart.d.ts +4 -4
  14. package/build/charts/PieChart.d.ts.map +1 -1
  15. package/build/charts/PieChart.js +36 -14
  16. package/build/charts/PieLabel.d.ts.map +1 -1
  17. package/build/charts/PieLabel.js +2 -1
  18. package/build/charts/RangeMarker.d.ts +3 -3
  19. package/build/charts/RangeMarker.d.ts.map +1 -1
  20. package/build/charts/RangeMarker.js +1 -1
  21. package/build/charts/axis/TimeAxis.d.ts +3 -3
  22. package/build/charts/axis/TimeAxis.d.ts.map +1 -1
  23. package/build/charts/axis/TimeAxis.js +70 -21
  24. package/build/charts/helpers/ValueAtFinder.d.ts +1 -1
  25. package/build/charts/helpers/ValueAtFinder.d.ts.map +1 -1
  26. package/build/charts/helpers/ValueAtFinder.js +5 -2
  27. package/build/data/StructuredSelector.js +3 -4
  28. package/build/data/createAccessorModelProxy.d.ts +6 -11
  29. package/build/data/createAccessorModelProxy.d.ts.map +1 -1
  30. package/build/data/createAccessorModelProxy.js +1 -3
  31. package/build/svg/Ellipse.d.ts +5 -4
  32. package/build/svg/Ellipse.d.ts.map +1 -1
  33. package/build/svg/Ellipse.js +9 -6
  34. package/build/svg/Line.d.ts +1 -0
  35. package/build/svg/Line.d.ts.map +1 -1
  36. package/build/svg/Line.js +4 -1
  37. package/build/svg/Text.d.ts +12 -6
  38. package/build/svg/Text.d.ts.map +1 -1
  39. package/build/svg/Text.js +12 -4
  40. package/build/ui/Controller.d.ts +2 -0
  41. package/build/ui/Controller.d.ts.map +1 -1
  42. package/build/ui/Controller.js +3 -0
  43. package/build/ui/HoverSync.d.ts.map +1 -1
  44. package/build/ui/HoverSync.js +7 -2
  45. package/build/ui/Prop.d.ts +1 -1
  46. package/build/ui/Prop.d.ts.map +1 -1
  47. package/build/ui/Text.d.ts +3 -3
  48. package/build/ui/Text.d.ts.map +1 -1
  49. package/build/ui/Text.js +5 -5
  50. package/build/ui/adapter/GroupAdapter.d.ts.map +1 -1
  51. package/build/ui/adapter/GroupAdapter.js +20 -10
  52. package/build/ui/app/History.js +1 -1
  53. package/build/widgets/List.d.ts.map +1 -1
  54. package/build/widgets/List.js +6 -7
  55. package/build/widgets/drag-drop/DropZone.d.ts +3 -3
  56. package/build/widgets/drag-drop/DropZone.d.ts.map +1 -1
  57. package/build/widgets/form/Calendar.d.ts.map +1 -1
  58. package/build/widgets/form/Calendar.js +30 -11
  59. package/build/widgets/form/ColorField.d.ts.map +1 -1
  60. package/build/widgets/form/ColorField.js +16 -7
  61. package/build/widgets/form/DateTimeField.d.ts.map +1 -1
  62. package/build/widgets/form/DateTimeField.js +23 -10
  63. package/build/widgets/form/Field.d.ts +2 -0
  64. package/build/widgets/form/Field.d.ts.map +1 -1
  65. package/build/widgets/form/Field.js +11 -5
  66. package/build/widgets/form/LookupField.d.ts +1 -1
  67. package/build/widgets/form/LookupField.d.ts.map +1 -1
  68. package/build/widgets/form/LookupField.js +6 -6
  69. package/build/widgets/form/MonthField.d.ts.map +1 -1
  70. package/build/widgets/form/MonthField.js +15 -7
  71. package/build/widgets/form/MonthPicker.d.ts +1 -2
  72. package/build/widgets/form/MonthPicker.d.ts.map +1 -1
  73. package/build/widgets/form/MonthPicker.js +84 -41
  74. package/build/widgets/form/NumberField.d.ts +2 -0
  75. package/build/widgets/form/NumberField.d.ts.map +1 -1
  76. package/build/widgets/form/NumberField.js +45 -15
  77. package/build/widgets/form/TextField.d.ts +1 -9
  78. package/build/widgets/form/TextField.d.ts.map +1 -1
  79. package/build/widgets/form/TextField.js +1 -1
  80. package/build/widgets/grid/Grid.d.ts +2 -2
  81. package/build/widgets/grid/Grid.d.ts.map +1 -1
  82. package/build/widgets/grid/Grid.js +14 -11
  83. package/build/widgets/grid/Pagination.d.ts.map +1 -1
  84. package/build/widgets/grid/Pagination.js +4 -4
  85. package/build/widgets/grid/TreeNode.d.ts.map +1 -1
  86. package/build/widgets/grid/TreeNode.js +10 -2
  87. package/build/widgets/icons/folder.d.ts.map +1 -1
  88. package/build/widgets/icons/folder.js +1 -0
  89. package/build/widgets/icons/forward.d.ts.map +1 -1
  90. package/build/widgets/icons/forward.js +4 -3
  91. package/build/widgets/icons/loading.d.ts.map +1 -1
  92. package/build/widgets/icons/loading.js +6 -5
  93. package/build/widgets/icons/square.d.ts.map +1 -1
  94. package/build/widgets/icons/square.js +3 -3
  95. package/build/widgets/index.d.ts +3 -1
  96. package/build/widgets/index.d.ts.map +1 -1
  97. package/build/widgets/index.js +3 -1
  98. package/build/widgets/overlay/ContextMenu.d.ts.map +1 -1
  99. package/build/widgets/overlay/ContextMenu.js +2 -0
  100. package/build/widgets/overlay/Dropdown.d.ts +2 -1
  101. package/build/widgets/overlay/Dropdown.d.ts.map +1 -1
  102. package/build/widgets/overlay/Dropdown.js +75 -20
  103. package/build/widgets/overlay/MsgBox.d.ts +1 -0
  104. package/build/widgets/overlay/MsgBox.d.ts.map +1 -1
  105. package/build/widgets/overlay/MsgBox.js +2 -2
  106. package/build/widgets/overlay/Overlay.d.ts +32 -2
  107. package/build/widgets/overlay/Overlay.d.ts.map +1 -1
  108. package/build/widgets/overlay/Overlay.js +47 -16
  109. package/build/widgets/overlay/Toast.d.ts +1 -1
  110. package/build/widgets/overlay/Toast.d.ts.map +1 -1
  111. package/build/widgets/overlay/Toast.js +4 -1
  112. package/build/widgets/overlay/Tooltip.d.ts +6 -0
  113. package/build/widgets/overlay/Tooltip.d.ts.map +1 -1
  114. package/build/widgets/overlay/Tooltip.js +24 -9
  115. package/build/widgets/overlay/Window.d.ts.map +1 -1
  116. package/build/widgets/overlay/Window.js +24 -9
  117. package/dist/charts.css +325 -272
  118. package/dist/charts.js +11 -5
  119. package/dist/data.js +2 -2
  120. package/dist/manifest.js +821 -809
  121. package/dist/svg.css +14 -8
  122. package/dist/svg.js +9 -1
  123. package/dist/ui.js +29 -16
  124. package/dist/widgets.css +997 -294
  125. package/dist/widgets.js +319 -126
  126. package/package.json +1 -1
  127. package/src/charts/Bar.scss +13 -10
  128. package/src/charts/BarGraph.scss +31 -29
  129. package/src/charts/BubbleGraph.scss +11 -8
  130. package/src/charts/Chart.ts +5 -3
  131. package/src/charts/Column.scss +13 -10
  132. package/src/charts/ColumnBarBase.tsx +255 -230
  133. package/src/charts/ColumnGraph.scss +13 -11
  134. package/src/charts/Gridlines.scss +10 -8
  135. package/src/charts/Legend.scss +57 -50
  136. package/src/charts/Legend.tsx +257 -213
  137. package/src/charts/LegendEntry.scss +35 -29
  138. package/src/charts/LineGraph.scss +28 -25
  139. package/src/charts/Marker.scss +12 -10
  140. package/src/charts/Marker.tsx +3 -2
  141. package/src/charts/MarkerLine.scss +11 -8
  142. package/src/charts/MarkerLine.tsx +196 -177
  143. package/src/charts/PieChart.scss +12 -9
  144. package/src/charts/PieChart.tsx +717 -591
  145. package/src/charts/PieLabel.tsx +99 -81
  146. package/src/charts/Range.scss +11 -8
  147. package/src/charts/RangeMarker.tsx +204 -187
  148. package/src/charts/ScatterGraph.scss +12 -9
  149. package/src/charts/axis/Axis.scss +6 -5
  150. package/src/charts/axis/CategoryAxis.scss +10 -8
  151. package/src/charts/axis/NumericAxis.scss +9 -6
  152. package/src/charts/axis/TimeAxis.scss +9 -6
  153. package/src/charts/axis/TimeAxis.tsx +753 -637
  154. package/src/charts/axis/index.scss +4 -5
  155. package/src/charts/axis/variables.scss +4 -2
  156. package/src/charts/helpers/ValueAtFinder.ts +19 -5
  157. package/src/charts/index.scss +16 -19
  158. package/src/charts/maps.scss +0 -0
  159. package/src/charts/palette.scss +11 -31
  160. package/src/charts/palette.variables.scss +23 -0
  161. package/src/charts/variables.scss +35 -3
  162. package/src/data/StructuredSelector.ts +2 -2
  163. package/src/data/createAccessorModelProxy.ts +66 -74
  164. package/src/index.scss +5 -6
  165. package/src/maps.scss +5 -0
  166. package/src/svg/Ellipse.tsx +62 -55
  167. package/src/svg/Line.tsx +57 -42
  168. package/src/svg/Svg.scss +6 -6
  169. package/src/svg/Text.scss +19 -0
  170. package/src/svg/Text.tsx +172 -116
  171. package/src/svg/index.scss +3 -2
  172. package/src/svg/maps.scss +0 -0
  173. package/src/svg/variables.scss +0 -0
  174. package/src/ui/Container.spec.ts +59 -0
  175. package/src/ui/Controller.spec.tsx +30 -0
  176. package/src/ui/Controller.ts +5 -0
  177. package/src/ui/HoverSync.tsx +179 -147
  178. package/src/ui/Prop.ts +1 -1
  179. package/src/ui/Text.ts +12 -9
  180. package/src/ui/adapter/GroupAdapter.spec.ts +42 -0
  181. package/src/ui/adapter/GroupAdapter.ts +25 -14
  182. package/src/ui/app/History.ts +1 -1
  183. package/src/ui/index.scss +1 -1
  184. package/src/ui/layout/LabelsLeftLayout.scss +5 -7
  185. package/src/ui/layout/LabelsTopLayout.scss +4 -6
  186. package/src/ui/layout/index.scss +2 -3
  187. package/src/ui/maps.scss +0 -0
  188. package/src/ui/variables.scss +1 -2
  189. package/src/util/index.scss +4 -2
  190. package/src/util/maps.scss +1 -0
  191. package/src/util/scss/besm.scss +15 -0
  192. package/src/util/scss/calc.scss +103 -11
  193. package/src/util/scss/defaults.scss +24 -0
  194. package/src/util/scss/elements.scss +78 -0
  195. package/src/util/scss/global.scss +15 -0
  196. package/src/util/scss/include.scss +17 -9
  197. package/src/util/scss/index.scss +1 -9
  198. package/src/util/scss/maps.scss +2 -0
  199. package/src/util/scss/pad-size.scss +9 -0
  200. package/src/util/scss/padding.scss +6 -0
  201. package/src/util/scss/screen-size.scss +5 -0
  202. package/src/util/scss/variables.scss +6 -0
  203. package/src/util/variables.scss +1 -0
  204. package/src/variables.scss +5 -217
  205. package/src/widgets/Button.maps.scss +103 -0
  206. package/src/widgets/Button.scss +33 -9
  207. package/src/widgets/Button.variables.scss +8 -104
  208. package/src/widgets/CxCredit.scss +2 -0
  209. package/src/widgets/FlexBox.scss +16 -11
  210. package/src/widgets/Heading.scss +6 -0
  211. package/src/widgets/HighlightedSearchText.scss +8 -1
  212. package/src/widgets/Icon.scss +6 -0
  213. package/src/widgets/List.scss +7 -0
  214. package/src/widgets/List.tsx +6 -7
  215. package/src/widgets/ProgressBar.scss +9 -0
  216. package/src/widgets/Resizer.scss +9 -7
  217. package/src/widgets/Section.scss +53 -56
  218. package/src/widgets/animations.scss +4 -2
  219. package/src/widgets/box.scss +47 -0
  220. package/src/widgets/drag-drop/DragClone.scss +12 -4
  221. package/src/widgets/drag-drop/DragHandle.scss +12 -6
  222. package/src/widgets/drag-drop/DragSource.scss +12 -6
  223. package/src/widgets/drag-drop/DropZone.scss +9 -0
  224. package/src/widgets/drag-drop/DropZone.tsx +3 -3
  225. package/src/widgets/drag-drop/index.scss +4 -4
  226. package/src/widgets/drag-drop/maps.scss +7 -0
  227. package/src/widgets/drag-drop/variables.scss +8 -5
  228. package/src/widgets/form/Calendar.maps.scss +54 -0
  229. package/src/widgets/form/Calendar.scss +49 -11
  230. package/src/widgets/form/Calendar.tsx +755 -653
  231. package/src/widgets/form/Calendar.variables.scss +3 -46
  232. package/src/widgets/form/Checkbox.maps.scss +34 -0
  233. package/src/widgets/form/Checkbox.scss +14 -3
  234. package/src/widgets/form/Checkbox.variables.scss +4 -36
  235. package/src/widgets/form/ColorField.scss +21 -2
  236. package/src/widgets/form/ColorField.tsx +485 -431
  237. package/src/widgets/form/ColorPicker.maps.scss +21 -0
  238. package/src/widgets/form/ColorPicker.scss +26 -9
  239. package/src/widgets/form/ColorPicker.variables.scss +3 -16
  240. package/src/widgets/form/DateTimeField.scss +54 -21
  241. package/src/widgets/form/DateTimeField.tsx +697 -615
  242. package/src/widgets/form/DateTimePicker.scss +14 -4
  243. package/src/widgets/form/Field.maps.scss +122 -0
  244. package/src/widgets/form/Field.scss +54 -18
  245. package/src/widgets/form/Field.tsx +611 -504
  246. package/src/widgets/form/Field.variables.scss +46 -0
  247. package/src/widgets/form/HelpText.scss +8 -5
  248. package/src/widgets/form/Label.scss +10 -3
  249. package/src/widgets/form/LookupField.maps.scss +26 -0
  250. package/src/widgets/form/LookupField.scss +54 -24
  251. package/src/widgets/form/LookupField.tsx +25 -21
  252. package/src/widgets/form/MonthField.scss +48 -26
  253. package/src/widgets/form/MonthField.tsx +645 -567
  254. package/src/widgets/form/MonthPicker.maps.scss +50 -0
  255. package/src/widgets/form/MonthPicker.scss +44 -35
  256. package/src/widgets/form/MonthPicker.tsx +954 -724
  257. package/src/widgets/form/MonthPicker.variables.scss +24 -0
  258. package/src/widgets/form/NumberField.scss +19 -2
  259. package/src/widgets/form/NumberField.tsx +576 -466
  260. package/src/widgets/form/Radio.maps.scss +36 -0
  261. package/src/widgets/form/Radio.scss +12 -2
  262. package/src/widgets/form/Radio.variables.scss +3 -42
  263. package/src/widgets/form/Select.scss +25 -9
  264. package/src/widgets/form/Slider.scss +23 -14
  265. package/src/widgets/form/Switch.scss +18 -8
  266. package/src/widgets/form/TextArea.scss +14 -1
  267. package/src/widgets/form/TextField.scss +24 -3
  268. package/src/widgets/form/TextField.tsx +9 -21
  269. package/src/widgets/form/UploadButton.scss +14 -6
  270. package/src/widgets/form/ValidationError.scss +10 -6
  271. package/src/widgets/form/Wheel.scss +14 -4
  272. package/src/widgets/form/index.scss +22 -24
  273. package/src/widgets/form/maps.scss +81 -0
  274. package/src/widgets/form/variables.scss +111 -355
  275. package/src/widgets/grid/Grid.scss +19 -2
  276. package/src/widgets/grid/Grid.spec.ts +42 -0
  277. package/src/widgets/grid/Grid.tsx +18 -13
  278. package/src/widgets/grid/Pagination.scss +11 -2
  279. package/src/widgets/grid/Pagination.tsx +110 -102
  280. package/src/widgets/grid/TreeNode.scss +25 -8
  281. package/src/widgets/grid/TreeNode.tsx +127 -116
  282. package/src/widgets/grid/index.scss +3 -4
  283. package/src/widgets/grid/maps.scss +110 -0
  284. package/src/widgets/grid/variables.scss +48 -137
  285. package/src/widgets/icons/folder.tsx +1 -2
  286. package/src/widgets/icons/forward.tsx +23 -20
  287. package/src/widgets/icons/loading.tsx +22 -19
  288. package/src/widgets/icons/square.tsx +20 -17
  289. package/src/widgets/index.scss +16 -16
  290. package/src/widgets/index.ts +63 -58
  291. package/src/widgets/lists.scss +42 -0
  292. package/src/widgets/maps.scss +139 -0
  293. package/src/widgets/nav/Link.scss +14 -1
  294. package/src/widgets/nav/Menu.scss +13 -7
  295. package/src/widgets/nav/Menu.variables.scss +1 -12
  296. package/src/widgets/nav/MenuItem.scss +21 -6
  297. package/src/widgets/nav/Scroller.scss +11 -2
  298. package/src/widgets/nav/Tab.maps.scss +78 -0
  299. package/src/widgets/nav/Tab.scss +12 -6
  300. package/src/widgets/nav/Tab.variables.scss +7 -76
  301. package/src/widgets/nav/cover.scss +6 -4
  302. package/src/widgets/nav/index.scss +6 -6
  303. package/src/widgets/nav/maps.scss +32 -0
  304. package/src/widgets/nav/variables.scss +4 -11
  305. package/src/widgets/overlay/ContextMenu.ts +3 -0
  306. package/src/widgets/overlay/Dropdown.scss +47 -16
  307. package/src/widgets/overlay/Dropdown.tsx +851 -676
  308. package/src/widgets/overlay/MsgBox.tsx +125 -111
  309. package/src/widgets/overlay/Overlay.scss +60 -40
  310. package/src/widgets/overlay/Overlay.tsx +948 -800
  311. package/src/widgets/overlay/Toast.scss +42 -34
  312. package/src/widgets/overlay/Toast.ts +11 -1
  313. package/src/widgets/overlay/Tooltip.scss +27 -96
  314. package/src/widgets/overlay/Tooltip.tsx +376 -309
  315. package/src/widgets/overlay/Window.maps.scss +51 -0
  316. package/src/widgets/overlay/Window.scss +17 -17
  317. package/src/widgets/overlay/Window.tsx +291 -236
  318. package/src/widgets/overlay/Window.variables.scss +2 -43
  319. package/src/widgets/overlay/index.d.ts +11 -11
  320. package/src/widgets/overlay/index.scss +6 -15
  321. package/src/widgets/overlay/maps.scss +44 -0
  322. package/src/widgets/overlay/variables.scss +11 -42
  323. package/src/widgets/variables.scss +33 -117
  324. package/src/global.scss +0 -14
@@ -1,5 +1,9 @@
1
1
  /** @jsxImportSource react */
2
- import { TooltipConfig, TooltipOptions, TooltipParentInstance } from "../overlay/tooltip-ops";
2
+ import {
3
+ TooltipConfig,
4
+ TooltipOptions,
5
+ TooltipParentInstance,
6
+ } from "../overlay/tooltip-ops";
3
7
  import { isSelector } from "../../data/isSelector";
4
8
  import { FocusManager } from "../../ui/FocusManager";
5
9
  import { Instance, PartialInstance } from "../../ui/Instance";
@@ -19,552 +23,650 @@ import { FieldIcon } from "./FieldIcon";
19
23
  import { HelpText } from "./HelpText";
20
24
  import { Label } from "./Label";
21
25
  import { ValidationError } from "./ValidationError";
22
- import { BooleanProp, ClassProp, Config, Prop, StringProp, StructuredProp, StyleProp } from "../../ui/Prop";
26
+ import {
27
+ BooleanProp,
28
+ ClassProp,
29
+ Config,
30
+ Prop,
31
+ StringProp,
32
+ StructuredProp,
33
+ StyleProp,
34
+ } from "../../ui/Prop";
23
35
  import type { TooltipInstance } from "../overlay";
24
36
  import type { FormRenderingContext } from "./ValidationGroup";
37
+ import { isObject } from "../../util";
25
38
 
26
39
  export interface FieldConfig extends PureContainerConfig, WidgetStyleConfig {
27
- /** Field label. For advanced use cases. */
28
- label?: StringProp | Config;
40
+ /** Field label. For advanced use cases. */
41
+ label?: StringProp | Config;
29
42
 
30
- /** Set to `material` to use custom label placement instruction. Used in Material theme to implement animated labels. */
31
- labelPlacement?: "material";
43
+ /** Set to `material` to use custom label placement instruction. Used in Material theme to implement animated labels. */
44
+ labelPlacement?: "material";
32
45
 
33
- /** Set to `material` to use custom help placement instruction. Used in Material theme to implement absolutely positioned validation messages. */
34
- helpPlacement?: "material";
46
+ /** Set to `material` to use custom help placement instruction. Used in Material theme to implement absolutely positioned validation messages. */
47
+ helpPlacement?: "material";
35
48
 
36
- /** Either `view` or `edit` (default). In `view` mode, the field is displayed as plain text. */
37
- mode?: Prop<"view" | "edit">;
49
+ /** Either `view` or `edit` (default). In `view` mode, the field is displayed as plain text. */
50
+ mode?: Prop<"view" | "edit">;
38
51
 
39
- /** Set to `true` to switch to widget view mode. Same as `mode="view"`. Default is false. */
40
- viewMode?: BooleanProp;
52
+ /** Set to `true` to switch to widget view mode. Same as `mode="view"`. Default is false. */
53
+ viewMode?: BooleanProp;
41
54
 
42
- id?: Prop<string | number>;
55
+ id?: Prop<string | number>;
43
56
 
44
- /** Used for validation. If error evaluates to non-null, the field is marked in red. */
45
- error?: StringProp;
57
+ /** Used for validation. If error evaluates to non-null, the field is marked in red. */
58
+ error?: StringProp;
46
59
 
47
- /** Style object applied to the input element. Used for setting visual elements, such as borders and backgrounds. */
48
- inputStyle?: StyleProp;
60
+ /** Style object applied to the input element. Used for setting visual elements, such as borders and backgrounds. */
61
+ inputStyle?: StyleProp;
49
62
 
50
- /** Additional CSS class applied to the input element. Used for setting visual elements, such as borders and backgrounds. */
51
- inputClass?: ClassProp;
63
+ /** Additional CSS class applied to the input element. Used for setting visual elements, such as borders and backgrounds. */
64
+ inputClass?: ClassProp;
52
65
 
53
- /** Additional attributes that should be rendered on the input element. E.g. inputAttrs={{ autoComplete: "off" }}. */
54
- inputAttrs?: Config;
66
+ /** Additional attributes that should be rendered on the input element. E.g. inputAttrs={{ autoComplete: "off" }}. */
67
+ inputAttrs?: Config;
55
68
 
56
- /** Text to be rendered in view mode when the field is empty. */
57
- emptyText?: StringProp;
69
+ /** Text to be rendered in view mode when the field is empty. */
70
+ emptyText?: StringProp;
58
71
 
59
- /** Set to `true` to make error indicators visible in pristine state. By default, validation errors are not shown until the user visits the field. */
60
- visited?: BooleanProp;
72
+ /** Set to `true` to make error indicators visible in pristine state. By default, validation errors are not shown until the user visits the field. */
73
+ visited?: BooleanProp;
61
74
 
62
- /** Set to `true` to automatically focus the field, after it renders for the first time. */
63
- autoFocus?: BooleanProp;
75
+ /** Set to `true` to automatically focus the field, after it renders for the first time. */
76
+ autoFocus?: BooleanProp;
64
77
 
65
- /** Defines how to present validation errors. Default mode is `tooltip`. Other options are `help` and `help-block`. */
66
- validationMode?: "tooltip" | "help" | "help-block";
78
+ /** Defines how to present validation errors. Default mode is `tooltip`. Other options are `help` and `help-block`. */
79
+ validationMode?: "tooltip" | "help" | "help-block";
67
80
 
68
- /** Defaults to `false`. Set to `true` to disable the field. */
69
- disabled?: BooleanProp;
81
+ /** Defaults to `false`. Set to `true` to disable the field. */
82
+ disabled?: BooleanProp;
70
83
 
71
- /** Defaults to `false`. Used to make the field required. */
72
- required?: BooleanProp;
84
+ /** The opposite of `disabled`. */
85
+ enabled?: BooleanProp;
73
86
 
74
- /** Used to indicate that required fields should not be marked as invalid before the user visits them. */
75
- suppressErrorsUntilVisited?: boolean;
87
+ /** Defaults to `false`. Used to make the field required. */
88
+ required?: BooleanProp;
76
89
 
77
- /** Error message used to indicate that field is required. */
78
- requiredText?: string;
90
+ /** Used to indicate that required fields should not be marked as invalid before the user visits them. */
91
+ suppressErrorsUntilVisited?: boolean;
79
92
 
80
- /** Append asterisk to the label to indicate a required field. */
81
- asterisk?: BooleanProp;
93
+ /** Error message used to indicate that field is required. */
94
+ requiredText?: string;
82
95
 
83
- /** Text displayed to the user to indicate that server-side validation is in progress. */
84
- validatingText?: string;
96
+ /** Append asterisk to the label to indicate a required field. */
97
+ asterisk?: BooleanProp;
85
98
 
86
- /** Text displayed to the user to indicate that server-side validation has thrown an exception. */
87
- validationExceptionText?: string;
99
+ /** Text displayed to the user to indicate that server-side validation is in progress. */
100
+ validatingText?: string;
88
101
 
89
- /** Configuration of the tooltip used to indicate validation errors. */
90
- errorTooltip?: Config;
102
+ /** Text displayed to the user to indicate that server-side validation has thrown an exception. */
103
+ validationExceptionText?: string;
91
104
 
92
- /** Tooltip configuration. */
93
- tooltip?: StringProp | StructuredProp;
105
+ /** Configuration of the tooltip used to indicate validation errors. */
106
+ errorTooltip?: Config;
94
107
 
95
- /** Indicates that `help` should be separated from the input with a whitespace. Default is `true`. */
96
- helpSpacer?: boolean;
108
+ /** Tooltip configuration. */
109
+ tooltip?: StringProp | StructuredProp;
97
110
 
98
- /** If set to `true` top level element will get additional CSS class indicating that input is focused. Default is `false`. */
99
- trackFocus?: boolean;
111
+ /** Indicates that `help` should be separated from the input with a whitespace. Default is `true`. */
112
+ helpSpacer?: boolean;
100
113
 
101
- /** Custom tab index */
102
- tabIndex?: StringProp;
114
+ /** If set to `true` top level element will get additional CSS class indicating that input is focused. Default is `false`. */
115
+ trackFocus?: boolean;
103
116
 
104
- /** Additional content to be displayed next to the field. */
105
- help?: string | Config;
117
+ /** Custom tab index */
118
+ tabIndex?: StringProp;
106
119
 
107
- /** Validation parameters to be passed to the validation function. */
108
- validationParams?: Config;
120
+ /** Additional content to be displayed next to the field. */
121
+ help?: string | Config;
109
122
 
110
- onValidationException?: string | ((error: unknown, instance: FieldInstance) => void);
123
+ /** Validation parameters to be passed to the validation function. */
124
+ validationParams?: Config;
111
125
 
112
- /** Value to be set in the store if the field is empty. Default value is null. */
113
- emptyValue?: unknown;
126
+ onValidationException?:
127
+ | string
128
+ | ((error: unknown, instance: FieldInstance) => void);
114
129
 
115
- /** Additional CSS style to be passed to the label object. */
116
- labelStyle?: StyleProp;
130
+ /** Value to be set in the store if the field is empty. Default value is null. */
131
+ emptyValue?: unknown;
117
132
 
118
- /** Additional CSS class to be passed to the label object. */
119
- labelClass?: ClassProp;
133
+ /** Additional CSS style to be passed to the label object. */
134
+ labelStyle?: StyleProp;
135
+
136
+ /** Additional CSS class to be passed to the label object. */
137
+ labelClass?: ClassProp;
120
138
  }
121
139
 
122
140
  export class FieldInstance<F extends Field<any, any> = Field<any, any>>
123
- extends Instance<F>
124
- implements TooltipParentInstance
141
+ extends Instance<F>
142
+ implements TooltipParentInstance
125
143
  {
126
- declare state: Record<string, any>;
127
- declare parentDisabled?: boolean;
128
- declare parentReadOnly?: boolean;
129
- declare parentViewMode?: boolean | string;
130
- declare parentTabOnEnterKey?: boolean;
131
- declare parentVisited?: boolean;
132
- declare tooltips: { [key: string]: TooltipInstance };
144
+ declare state: Record<string, any>;
145
+ declare parentDisabled?: boolean;
146
+ declare parentReadOnly?: boolean;
147
+ declare parentViewMode?: boolean | string;
148
+ declare parentTabOnEnterKey?: boolean;
149
+ declare parentVisited?: boolean;
150
+ declare tooltips: { [key: string]: TooltipInstance };
133
151
  }
134
152
 
135
153
  export class Field<
136
- Config extends FieldConfig = FieldConfig,
137
- InstanceType extends FieldInstance<any> = FieldInstance<any>,
154
+ Config extends FieldConfig = FieldConfig,
155
+ InstanceType extends FieldInstance<any> = FieldInstance<any>,
138
156
  > extends PureContainerBase<Config, InstanceType> {
139
- declare public inputStyle?: Record<string, unknown> | string;
140
- declare public validationMode?: string;
141
- declare public errorTooltip?: Record<string, unknown>;
142
- declare public tooltip?: TooltipConfig;
143
- declare public help?: Record<string, unknown> | string;
144
- declare public label?: Record<string, unknown> | string;
145
- declare public mod?: Record<string, unknown>;
146
- declare public disabled?: boolean;
147
- declare public required?: boolean;
148
- declare public asterisk?: boolean;
149
- declare public labelStyle?: Record<string, unknown> | string;
150
- declare public labelClass?: string;
151
- declare public icon?: null | string;
152
- declare public visited?: boolean;
153
- declare public labelPlacement?: string | boolean;
154
- declare public helpPlacement?: string | boolean;
155
- declare public emptyValue?: unknown;
156
- declare public requiredText?: string;
157
- declare public validatingText?: string;
158
- declare public onValidate?:
159
- | string
160
- | ((value: unknown, instance: Instance, validationParams: Record<string, unknown>) => unknown);
161
- declare public validationExceptionText?: string;
162
- declare public onValidationException?: string | ((error: unknown, instance: Instance) => void);
163
- declare public onKeyDown?: string | ((e: React.KeyboardEvent, instance: Instance) => boolean | void);
164
- declare public suppressErrorsUntilVisited?: boolean;
165
- declare public autoFocus?: boolean;
166
- declare public helpSpacer?: boolean;
167
- declare public trackFocus?: boolean;
168
- declare public baseClass: string;
169
-
170
- public declareData(...args: Record<string, unknown>[]): void {
171
- super.declareData(
172
- {
173
- label: undefined,
174
- labelWidth: undefined,
175
- mode: undefined,
176
- viewMode: undefined,
177
- id: undefined,
178
- error: undefined,
179
- inputStyle: { structured: true },
180
- inputClass: { structured: true },
181
- inputAttrs: { structured: true },
182
- emptyText: undefined,
183
- visited: undefined,
184
- autoFocus: undefined,
185
- tabOnEnterKey: undefined,
186
- tabIndex: undefined,
187
- validationParams: { structured: true },
188
- },
189
- ...args,
190
- );
191
- }
192
-
193
- public init(): void {
194
- this.inputStyle = parseStyle(this.inputStyle);
195
- super.init();
196
- }
197
-
198
- public initComponents(_context: RenderingContext, instance: Instance): void {
199
- if (this.validationMode == "tooltip" && isUndefined(this.errorTooltip)) {
200
- this.errorTooltip = {
201
- text: { bind: "$error" },
202
- mod: "error",
203
- ...(this.errorTooltip || {}),
204
- };
205
- }
206
-
207
- if (isUndefined(this.help)) {
208
- switch (this.validationMode) {
209
- case "help":
210
- case "help-inline":
211
- this.help = ValidationError as any;
212
- break;
213
-
214
- case "help-block":
215
- this.help = {
216
- type: ValidationError as any,
217
- mod: "block",
218
- };
219
- break;
220
- }
221
- }
222
-
223
- if (this.help != null) {
224
- let helpConfig: any = {};
225
-
226
- if ((this.help as any).isComponentType) helpConfig = this.help;
227
- else if (isSelector(this.help)) helpConfig.text = this.help;
228
- else Object.assign(helpConfig, this.help);
229
-
230
- this.help = HelpText.create(helpConfig) as any;
231
- }
232
-
233
- if (this.label != null) {
234
- let labelConfig: any = {
235
- mod: this.mod,
236
- disabled: this.disabled,
237
- required: this.required,
238
- asterisk: this.asterisk,
239
- style: this.labelStyle,
240
- class: this.labelClass,
241
- };
242
-
243
- if ((this.label as any).isComponentType) labelConfig = this.label;
244
- else if (isSelector(this.label)) labelConfig.text = this.label;
245
- else Object.assign(labelConfig, this.label);
246
-
247
- this.label = Label.create(labelConfig) as any;
248
- }
249
-
250
- if (this.icon != null) {
251
- let iconConfig: any = {
252
- className: this.CSS.element(this.baseClass, "icon"),
253
- };
254
- if (isSelector(this.icon)) iconConfig.name = this.icon;
255
- else Object.assign(iconConfig, this.icon);
256
-
257
- this.icon = FieldIcon.create(iconConfig) as any;
157
+ declare public inputStyle?: Record<string, unknown> | string;
158
+ declare public validationMode?: string;
159
+ declare public errorTooltip?: Record<string, unknown>;
160
+ declare public tooltip?: TooltipConfig;
161
+ declare public help?: Record<string, unknown> | string;
162
+ declare public label?: Record<string, unknown> | string;
163
+ declare public mod?: Record<string, unknown>;
164
+ declare public disabled?: boolean;
165
+ declare public required?: boolean;
166
+ declare public asterisk?: boolean;
167
+ declare public labelStyle?: Record<string, unknown> | string;
168
+ declare public labelClass?: string;
169
+ declare public icon?: null | string;
170
+ declare public visited?: boolean;
171
+ declare public labelPlacement?: string | boolean;
172
+ declare public helpPlacement?: string | boolean;
173
+ declare public emptyValue?: unknown;
174
+ declare public requiredText?: string;
175
+ declare public validatingText?: string;
176
+ declare public onValidate?:
177
+ | string
178
+ | ((
179
+ value: unknown,
180
+ instance: Instance,
181
+ validationParams: Record<string, unknown>,
182
+ ) => unknown);
183
+ declare public validationExceptionText?: string;
184
+ declare public onValidationException?:
185
+ | string
186
+ | ((error: unknown, instance: Instance) => void);
187
+ declare public onKeyDown?:
188
+ | string
189
+ | ((e: React.KeyboardEvent, instance: Instance) => boolean | void);
190
+ declare public suppressErrorsUntilVisited?: boolean;
191
+ declare public autoFocus?: boolean;
192
+ declare public helpSpacer?: boolean;
193
+ declare public trackFocus?: boolean;
194
+ declare public baseClass: string;
195
+
196
+ public declareData(...args: Record<string, unknown>[]): void {
197
+ super.declareData(
198
+ {
199
+ label: undefined,
200
+ labelWidth: undefined,
201
+ mode: undefined,
202
+ viewMode: undefined,
203
+ id: undefined,
204
+ error: undefined,
205
+ inputStyle: { structured: true },
206
+ inputClass: { structured: true },
207
+ inputAttrs: { structured: true },
208
+ emptyText: undefined,
209
+ visited: undefined,
210
+ autoFocus: undefined,
211
+ tabOnEnterKey: undefined,
212
+ tabIndex: undefined,
213
+ validationParams: { structured: true },
214
+ },
215
+ ...args,
216
+ );
217
+ }
218
+
219
+ public init(): void {
220
+ this.inputStyle = parseStyle(this.inputStyle);
221
+ super.init();
222
+ }
223
+
224
+ public initComponents(_context: RenderingContext, instance: Instance): void {
225
+ if (
226
+ this.validationMode == "tooltip" &&
227
+ (isUndefined(this.errorTooltip) || isObject(this.errorTooltip))
228
+ ) {
229
+ this.errorTooltip = {
230
+ text: { bind: "$error" },
231
+ mod: "error",
232
+ ...this.errorTooltip,
233
+ };
234
+ }
235
+
236
+ if (isUndefined(this.help)) {
237
+ switch (this.validationMode) {
238
+ case "help":
239
+ case "help-inline":
240
+ this.help = ValidationError as any;
241
+ break;
242
+
243
+ case "help-block":
244
+ this.help = {
245
+ type: ValidationError as any,
246
+ mod: "block",
247
+ };
248
+ break;
258
249
  }
259
-
260
- super.initComponents({
261
- label: this.label,
262
- help: this.help,
263
- icon: this.icon,
264
- });
265
- }
266
-
267
- public initState(_context: RenderingContext, instance: InstanceType): void {
268
- instance.state = {
269
- inputError: false,
270
- visited: this.visited === true,
250
+ }
251
+
252
+ if (this.help != null) {
253
+ let helpConfig: any = {};
254
+
255
+ if ((this.help as any).isComponentType) helpConfig = this.help;
256
+ else if (isSelector(this.help)) helpConfig.text = this.help;
257
+ else Object.assign(helpConfig, this.help);
258
+
259
+ this.help = HelpText.create(helpConfig) as any;
260
+ }
261
+
262
+ if (this.label != null) {
263
+ let labelConfig: any = {
264
+ mod: this.mod,
265
+ disabled: this.disabled,
266
+ required: this.required,
267
+ asterisk: this.asterisk,
268
+ style: this.labelStyle,
269
+ class: this.labelClass,
271
270
  };
272
- }
273
-
274
- public prepareData(context: FormRenderingContext, instance: InstanceType, ...args: Record<string, unknown>[]): void {
275
- let { data, state } = instance;
276
- if (!data.id) data.id = "fld-" + instance.id;
277
271
 
278
- data._disabled = data.disabled;
279
- data._readOnly = data.readOnly;
280
- data._viewMode = data.mode === "view" || data.viewMode;
281
- data._tabOnEnterKey = data.tabOnEnterKey;
282
- data.validationValue = this.getValidationValue(data);
283
- instance.parentDisabled = context.parentDisabled;
284
- instance.parentReadOnly = context.parentReadOnly;
285
- instance.parentViewMode = context.parentViewMode;
286
- instance.parentTabOnEnterKey = context.parentTabOnEnterKey;
287
- instance.parentVisited = context.parentVisited;
272
+ if ((this.label as any).isComponentType) labelConfig = this.label;
273
+ else if (isSelector(this.label)) labelConfig.text = this.label;
274
+ else Object.assign(labelConfig, this.label);
288
275
 
289
- if (typeof data.enabled !== "undefined") data._disabled = !data.enabled;
276
+ this.label = Label.create(labelConfig) as any;
277
+ }
290
278
 
279
+ if (this.icon != null) {
280
+ let iconConfig: any = {
281
+ className: this.CSS.element(this.baseClass, "icon"),
282
+ };
283
+ if (isSelector(this.icon)) iconConfig.name = this.icon;
284
+ else Object.assign(iconConfig, this.icon);
285
+
286
+ this.icon = FieldIcon.create(iconConfig) as any;
287
+ }
288
+
289
+ super.initComponents({
290
+ label: this.label,
291
+ help: this.help,
292
+ icon: this.icon,
293
+ });
294
+ }
295
+
296
+ public initState(_context: RenderingContext, instance: InstanceType): void {
297
+ instance.state = {
298
+ inputError: false,
299
+ visited: this.visited === true,
300
+ };
301
+ }
302
+
303
+ public prepareData(
304
+ context: FormRenderingContext,
305
+ instance: InstanceType,
306
+ ...args: Record<string, unknown>[]
307
+ ): void {
308
+ let { data, state } = instance;
309
+ if (!data.id) data.id = "fld-" + instance.id;
310
+
311
+ data._disabled = data.disabled;
312
+ data._readOnly = data.readOnly;
313
+ data._viewMode = data.mode === "view" || data.viewMode;
314
+ data._tabOnEnterKey = data.tabOnEnterKey;
315
+ data.validationValue = this.getValidationValue(data);
316
+ instance.parentDisabled = context.parentDisabled;
317
+ instance.parentReadOnly = context.parentReadOnly;
318
+ instance.parentViewMode = context.parentViewMode;
319
+ instance.parentTabOnEnterKey = context.parentTabOnEnterKey;
320
+ instance.parentVisited = context.parentVisited;
321
+
322
+ if (typeof data.enabled !== "undefined") data._disabled = !data.enabled;
323
+
324
+ this.disableOrValidate(context, instance);
325
+
326
+ data.inputStyle = parseStyle(data.inputStyle);
327
+
328
+ if (this.labelPlacement && this.label)
329
+ data.mod = [data.mod, "label-placement-" + this.labelPlacement];
330
+
331
+ if (this.helpPlacement && this.help)
332
+ data.mod = [data.mod, "help-placement-" + this.helpPlacement];
333
+
334
+ data.empty = this.isEmpty(data);
335
+
336
+ super.prepareData(context, instance);
337
+ }
338
+
339
+ protected disableOrValidate(
340
+ context: FormRenderingContext,
341
+ instance: Instance,
342
+ ): void {
343
+ let { data, state } = instance;
344
+
345
+ //if the parent is strict and sets some flag to true, it is not allowed to overrule that flag by field settings
346
+
347
+ data.disabled = coalesce(
348
+ context.parentStrict ? context.parentDisabled : null,
349
+ data._disabled,
350
+ context.parentDisabled,
351
+ );
352
+ data.readOnly = coalesce(
353
+ context.parentStrict ? context.parentReadOnly : null,
354
+ data._readOnly,
355
+ context.parentReadOnly,
356
+ );
357
+ data.viewMode = coalesce(
358
+ context.parentStrict ? context.parentViewMode : null,
359
+ data._viewMode,
360
+ context.parentViewMode,
361
+ );
362
+ data.tabOnEnterKey = coalesce(
363
+ context.parentStrict ? context.parentTabOnEnterKey : null,
364
+ data._tabOnEnterKey,
365
+ context.parentTabOnEnterKey,
366
+ );
367
+ data.visited = coalesce(
368
+ context.parentStrict ? context.parentVisited : null,
369
+ data.visited,
370
+ context.parentVisited,
371
+ );
372
+
373
+ if (!data.error && !data.disabled && !data.viewMode)
374
+ this.validate(context, instance);
375
+
376
+ if (data.visited && !state?.visited) {
377
+ //feels hacky but it should be ok since we're in the middle of a new render cycle
378
+ state!.visited = true;
379
+ }
380
+
381
+ data.stateMods = {
382
+ ...data.stateMods,
383
+ disabled: data.disabled,
384
+ "edit-mode": !data.viewMode,
385
+ "view-mode": data.viewMode,
386
+ };
387
+ }
388
+
389
+ explore(context: FormRenderingContext, instance: InstanceType): void {
390
+ let { data, state } = instance;
391
+
392
+ instance.parentDisabled = context.parentDisabled;
393
+ instance.parentReadOnly = context.parentReadOnly;
394
+ instance.parentViewMode = context.parentViewMode;
395
+ instance.parentTabOnEnterKey = context.parentTabOnEnterKey;
396
+ instance.parentVisited = context.parentVisited;
397
+
398
+ if (
399
+ instance.cache("parentDisabled", context.parentDisabled) ||
400
+ instance.cache("parentReadOnly", context.parentReadOnly) ||
401
+ instance.cache("parentViewMode", context.parentViewMode) ||
402
+ instance.cache("parentTabOnEnterKey", context.parentTabOnEnterKey) ||
403
+ instance.cache("parentVisited", context.parentVisited)
404
+ ) {
405
+ instance.markShouldUpdate(context);
291
406
  this.disableOrValidate(context, instance);
407
+ this.prepareCSS(context, instance);
408
+ }
292
409
 
293
- data.inputStyle = parseStyle(data.inputStyle);
294
-
295
- if (this.labelPlacement && this.label) data.mod = [data.mod, "label-placement-" + this.labelPlacement];
296
-
297
- if (this.helpPlacement && this.help) data.mod = [data.mod, "help-placement-" + this.helpPlacement];
298
-
299
- data.empty = this.isEmpty(data);
300
-
301
- super.prepareData(context, instance);
302
- }
303
-
304
- protected disableOrValidate(context: FormRenderingContext, instance: Instance): void {
305
- let { data, state } = instance;
306
-
307
- //if the parent is strict and sets some flag to true, it is not allowed to overrule that flag by field settings
308
-
309
- data.disabled = coalesce(
310
- context.parentStrict ? context.parentDisabled : null,
311
- data._disabled,
312
- context.parentDisabled,
313
- );
314
- data.readOnly = coalesce(
315
- context.parentStrict ? context.parentReadOnly : null,
316
- data._readOnly,
317
- context.parentReadOnly,
318
- );
319
- data.viewMode = coalesce(
320
- context.parentStrict ? context.parentViewMode : null,
321
- data._viewMode,
322
- context.parentViewMode,
323
- );
324
- data.tabOnEnterKey = coalesce(
325
- context.parentStrict ? context.parentTabOnEnterKey : null,
326
- data._tabOnEnterKey,
327
- context.parentTabOnEnterKey,
328
- );
329
- data.visited = coalesce(context.parentStrict ? context.parentVisited : null, data.visited, context.parentVisited);
330
-
331
- if (!data.error && !data.disabled && !data.viewMode) this.validate(context, instance);
332
-
333
- if (data.visited && !state?.visited) {
334
- //feels hacky but it should be ok since we're in the middle of a new render cycle
335
- state!.visited = true;
336
- }
337
-
338
- data.stateMods = {
339
- ...data.stateMods,
340
- disabled: data.disabled,
341
- "edit-mode": !data.viewMode,
342
- "view-mode": data.viewMode,
410
+ if (!context.validation)
411
+ context.validation = {
412
+ errors: [],
343
413
  };
344
- }
345
-
346
- explore(context: FormRenderingContext, instance: InstanceType): void {
347
- let { data, state } = instance;
348
-
349
- instance.parentDisabled = context.parentDisabled;
350
- instance.parentReadOnly = context.parentReadOnly;
351
- instance.parentViewMode = context.parentViewMode;
352
- instance.parentTabOnEnterKey = context.parentTabOnEnterKey;
353
- instance.parentVisited = context.parentVisited;
354
-
355
- if (
356
- instance.cache("parentDisabled", context.parentDisabled) ||
357
- instance.cache("parentReadOnly", context.parentReadOnly) ||
358
- instance.cache("parentViewMode", context.parentViewMode) ||
359
- instance.cache("parentTabOnEnterKey", context.parentTabOnEnterKey) ||
360
- instance.cache("parentVisited", context.parentVisited)
361
- ) {
362
- instance.markShouldUpdate(context);
363
- this.disableOrValidate(context, instance);
364
- this.prepareCSS(context, instance);
365
- }
366
414
 
367
- if (!context.validation)
368
- context.validation = {
369
- errors: [],
370
- };
371
-
372
- if (data.error) {
373
- context.validation.errors.push({
374
- fieldId: data.id,
375
- message: data.error,
376
- visited: state?.visited,
377
- type: "error",
378
- });
379
- }
380
-
381
- context.push("lastFieldId", data.id);
382
- super.explore(context, instance);
383
- }
384
-
385
- exploreCleanup(context: FormRenderingContext, instance: Instance): void {
386
- context.pop("lastFieldId");
387
- }
388
-
389
- isEmpty(data: Record<string, unknown>): boolean {
390
- return data.value == null || data.value === this.emptyValue;
391
- }
392
-
393
- validateRequired(context: FormRenderingContext, instance: Instance): string | undefined {
394
- let { data } = instance;
395
- if (this.isEmpty(data)) return this.requiredText;
396
- }
397
-
398
- getValidationValue(data: Record<string, unknown>): unknown {
399
- return data.value;
400
- }
401
-
402
- validate(context: FormRenderingContext, instance: Instance): void {
403
- let { data } = instance;
404
- let state = instance.state || {};
405
-
406
- let empty = this.isEmpty(data);
407
-
408
- if (!data.error) {
409
- if (state.inputError) data.error = state.inputError;
410
- else if (state.validating && !empty) data.error = this.validatingText;
411
- else if (
412
- state.validationError &&
413
- data.validationValue === state.lastValidatedValue &&
414
- shallowEquals(data.validationParams, state.lastValidationParams)
415
- )
416
- data.error = state.validationError;
417
- else if (data.required) data.error = this.validateRequired(context, instance);
418
- }
415
+ if (data.error) {
416
+ context.validation.errors.push({
417
+ fieldId: data.id,
418
+ message: data.error,
419
+ visited: state?.visited,
420
+ type: "error",
421
+ });
422
+ }
423
+
424
+ context.push("lastFieldId", data.id);
425
+ super.explore(context, instance);
426
+ }
427
+
428
+ exploreCleanup(context: FormRenderingContext, instance: Instance): void {
429
+ context.pop("lastFieldId");
430
+ }
431
+
432
+ isEmpty(data: Record<string, unknown>): boolean {
433
+ return data.value == null || data.value === this.emptyValue;
434
+ }
435
+
436
+ validateRequired(
437
+ context: FormRenderingContext,
438
+ instance: Instance,
439
+ ): string | undefined {
440
+ let { data } = instance;
441
+ if (this.isEmpty(data)) return this.requiredText;
442
+ }
443
+
444
+ getValidationValue(data: Record<string, unknown>): unknown {
445
+ return data.value;
446
+ }
447
+
448
+ validate(context: FormRenderingContext, instance: Instance): void {
449
+ let { data } = instance;
450
+ let state = instance.state || {};
451
+
452
+ let empty = this.isEmpty(data);
453
+
454
+ if (!data.error) {
455
+ if (state.inputError) data.error = state.inputError;
456
+ else if (state.validating && !empty) data.error = this.validatingText;
457
+ else if (
458
+ state.validationError &&
459
+ data.validationValue === state.lastValidatedValue &&
460
+ shallowEquals(data.validationParams, state.lastValidationParams)
461
+ )
462
+ data.error = state.validationError;
463
+ else if (data.required)
464
+ data.error = this.validateRequired(context, instance);
465
+ }
466
+
467
+ if (
468
+ !empty &&
469
+ !state.validating &&
470
+ !data.error &&
471
+ this.onValidate &&
472
+ (!state.previouslyValidated ||
473
+ data.validationValue != state.lastValidatedValue ||
474
+ data.validationParams != state.lastValidationParams)
475
+ ) {
476
+ let result = instance.invoke(
477
+ "onValidate",
478
+ data.validationValue,
479
+ instance,
480
+ data.validationParams,
481
+ );
482
+ if (isPromise(result)) {
483
+ data.error = this.validatingText;
484
+ instance.setState({
485
+ validating: true,
486
+ lastValidatedValue: data.validationValue,
487
+ previouslyValidated: true,
488
+ lastValidationParams: data.validationParams,
489
+ });
490
+ result
491
+ .then((r) => {
492
+ let { data, state } = instance;
493
+ let error =
494
+ data.validationValue == state?.lastValidatedValue &&
495
+ shallowEquals(data.validationParams, state?.lastValidationParams)
496
+ ? r
497
+ : this.validatingText; //parameters changed, this will be revalidated
419
498
 
420
- if (
421
- !empty &&
422
- !state.validating &&
423
- !data.error &&
424
- this.onValidate &&
425
- (!state.previouslyValidated ||
426
- data.validationValue != state.lastValidatedValue ||
427
- data.validationParams != state.lastValidationParams)
428
- ) {
429
- let result = instance.invoke("onValidate", data.validationValue, instance, data.validationParams);
430
- if (isPromise(result)) {
431
- data.error = this.validatingText;
432
499
  instance.setState({
433
- validating: true,
434
- lastValidatedValue: data.validationValue,
435
- previouslyValidated: true,
436
- lastValidationParams: data.validationParams,
500
+ validating: false,
501
+ validationError: error,
437
502
  });
438
- result
439
- .then((r) => {
440
- let { data, state } = instance;
441
- let error =
442
- data.validationValue == state?.lastValidatedValue &&
443
- shallowEquals(data.validationParams, state?.lastValidationParams)
444
- ? r
445
- : this.validatingText; //parameters changed, this will be revalidated
446
-
447
- instance.setState({
448
- validating: false,
449
- validationError: error,
450
- });
451
- })
452
- .catch((e) => {
453
- instance.setState({
454
- validating: false,
455
- validationError: this.validationExceptionText,
456
- });
457
- if (this.onValidationException) instance.invoke("onValidationException", e, instance);
458
- else {
459
- Console.warn("Unhandled validation exception:", e);
460
- }
461
- });
462
- } else {
463
- data.error = result;
464
- }
465
- }
466
- }
467
-
468
- renderLabel(context: RenderingContext, instance: Instance, key: string): React.ReactNode {
469
- if (instance.components?.label) return getContent(instance.components.label.vdom);
470
- }
471
-
472
- renderInput(context: RenderingContext, instance: Instance, key: string): React.ReactNode {
473
- throw new Error("Not implemented.");
474
- }
475
-
476
- renderHelp(context: RenderingContext, instance: Instance, key: string): React.ReactNode {
477
- if (instance.components?.help) return getContent(instance.components.help.render(context));
478
- }
479
-
480
- renderIcon(context: RenderingContext, instance: Instance, key: string): React.ReactNode {
481
- if (instance.components?.icon) return getContent(instance.components.icon.render(context));
482
- }
483
-
484
- formatValue(context: RenderingContext, { data }: Instance): string | React.ReactNode {
485
- return data.text || data.value;
486
- }
487
-
488
- renderValue(context: RenderingContext, instance: FieldInstance, key?: string | number): React.ReactNode {
489
- let text = this.formatValue(context, instance as Instance);
490
- if (text) {
491
- return (
492
- <span
493
- key={key}
494
- onMouseMove={(e: any) => {
495
- const tooltip = getFieldTooltip(instance);
496
- if (tooltip) (tooltipMouseMove as any)(e, tooltip, null, null);
497
- }}
498
- onMouseLeave={(e: any) => {
499
- const tooltip = getFieldTooltip(instance);
500
- if (tooltip) (tooltipMouseLeave as any)(e, tooltip, null, null);
501
- }}
502
- >
503
- {text}
504
- </span>
505
- );
503
+ })
504
+ .catch((e) => {
505
+ instance.setState({
506
+ validating: false,
507
+ validationError: this.validationExceptionText,
508
+ });
509
+ if (this.onValidationException)
510
+ instance.invoke("onValidationException", e, instance);
511
+ else {
512
+ Console.warn("Unhandled validation exception:", e);
513
+ }
514
+ });
515
+ } else {
516
+ data.error = result;
506
517
  }
507
- }
508
-
509
- protected renderContent(context: RenderingContext, instance: FieldInstance, key: string): React.ReactNode {
510
- let content = this.renderValue(context, instance, key) || this.renderEmptyText(context, instance, key);
511
- return this.renderWrap(context, instance, key, content);
512
- }
513
-
514
- protected renderWrap(
515
- context: RenderingContext,
516
- instance: Instance,
517
- key: string,
518
- content: React.ReactNode,
519
- ): React.ReactNode {
520
- let { data } = instance;
521
- let interactive = !data.viewMode && !data.disabled;
522
- return (
523
- <div
524
- key={key}
525
- className={data.classNames}
526
- style={data.style}
527
- onMouseDown={interactive ? stopPropagation : undefined}
528
- onTouchStart={interactive ? stopPropagation : undefined}
529
- >
530
- {content}
531
- {this.labelPlacement && this.renderLabel(context, instance, "label")}
532
- </div>
533
- );
534
- }
535
-
536
- protected renderEmptyText(_context: RenderingContext, { data }: Instance, key: string): React.ReactNode {
518
+ }
519
+ }
520
+
521
+ renderLabel(
522
+ context: RenderingContext,
523
+ instance: Instance,
524
+ key: string,
525
+ ): React.ReactNode {
526
+ if (instance.components?.label)
527
+ return getContent(instance.components.label.vdom);
528
+ }
529
+
530
+ renderInput(
531
+ context: RenderingContext,
532
+ instance: Instance,
533
+ key: string,
534
+ ): React.ReactNode {
535
+ throw new Error("Not implemented.");
536
+ }
537
+
538
+ renderHelp(
539
+ context: RenderingContext,
540
+ instance: Instance,
541
+ key: string,
542
+ ): React.ReactNode {
543
+ if (instance.components?.help)
544
+ return getContent(instance.components.help.render(context));
545
+ }
546
+
547
+ renderIcon(
548
+ context: RenderingContext,
549
+ instance: Instance,
550
+ key: string,
551
+ ): React.ReactNode {
552
+ if (instance.components?.icon)
553
+ return getContent(instance.components.icon.render(context));
554
+ }
555
+
556
+ formatValue(
557
+ context: RenderingContext,
558
+ { data }: Instance,
559
+ ): string | React.ReactNode {
560
+ return data.text || data.value;
561
+ }
562
+
563
+ renderValue(
564
+ context: RenderingContext,
565
+ instance: FieldInstance,
566
+ key?: string | number,
567
+ ): React.ReactNode {
568
+ let text = this.formatValue(context, instance as Instance);
569
+ if (text) {
537
570
  return (
538
- <span key={key} className={this.CSS.element(this.baseClass, "empty-text")}>
539
- {data.emptyText || <span>&nbsp;</span>}
540
- </span>
571
+ <span
572
+ key={key}
573
+ onMouseMove={(e: any) => {
574
+ const tooltip = getFieldTooltip(instance);
575
+ if (tooltip) (tooltipMouseMove as any)(e, tooltip, null, null);
576
+ }}
577
+ onMouseLeave={(e: any) => {
578
+ const tooltip = getFieldTooltip(instance);
579
+ if (tooltip) (tooltipMouseLeave as any)(e, tooltip, null, null);
580
+ }}
581
+ >
582
+ {text}
583
+ </span>
541
584
  );
542
- }
543
-
544
- public render(context: RenderingContext, instance: InstanceType, key: string): Record<string, React.ReactNode> {
545
- let { data } = instance;
546
- let content = !data.viewMode
547
- ? this.renderInput(context, instance, key)
548
- : this.renderContent(context, instance, key);
549
-
550
- return {
551
- label: !this.labelPlacement && this.renderLabel(context, instance, key),
552
- content: content,
553
- helpSpacer: this.helpSpacer && instance.components?.help ? " " : undefined,
554
- help: !this.helpPlacement && this.renderHelp(context, instance, key),
555
- };
556
- }
557
-
558
- public handleKeyDown(e: React.KeyboardEvent, instance: Instance): boolean | void {
559
- if (this.onKeyDown && instance.invoke("onKeyDown", e, instance) === false) return false;
560
-
561
- if (instance.data.tabOnEnterKey && e.keyCode === 13) {
562
- let target = e.target;
563
- setTimeout(() => {
564
- if (!instance.state?.inputError) (FocusManager as any).focusNext(target);
565
- }, 10);
566
- }
567
- }
585
+ }
586
+ }
587
+
588
+ protected renderContent(
589
+ context: RenderingContext,
590
+ instance: FieldInstance,
591
+ key: string,
592
+ ): React.ReactNode {
593
+ let content =
594
+ this.renderValue(context, instance, key) ||
595
+ this.renderEmptyText(context, instance, key);
596
+ return this.renderWrap(context, instance, key, content);
597
+ }
598
+
599
+ protected renderWrap(
600
+ context: RenderingContext,
601
+ instance: Instance,
602
+ key: string,
603
+ content: React.ReactNode,
604
+ ): React.ReactNode {
605
+ let { data } = instance;
606
+ let interactive = !data.viewMode && !data.disabled;
607
+ return (
608
+ <div
609
+ key={key}
610
+ className={data.classNames}
611
+ style={data.style}
612
+ onMouseDown={interactive ? stopPropagation : undefined}
613
+ onTouchStart={interactive ? stopPropagation : undefined}
614
+ >
615
+ {content}
616
+ {this.labelPlacement && this.renderLabel(context, instance, "label")}
617
+ </div>
618
+ );
619
+ }
620
+
621
+ protected renderEmptyText(
622
+ _context: RenderingContext,
623
+ { data }: Instance,
624
+ key: string,
625
+ ): React.ReactNode {
626
+ return (
627
+ <span
628
+ key={key}
629
+ className={this.CSS.element(this.baseClass, "empty-text")}
630
+ >
631
+ {data.emptyText || <span>&nbsp;</span>}
632
+ </span>
633
+ );
634
+ }
635
+
636
+ public render(
637
+ context: RenderingContext,
638
+ instance: InstanceType,
639
+ key: string,
640
+ ): Record<string, React.ReactNode> {
641
+ let { data } = instance;
642
+ let content = !data.viewMode
643
+ ? this.renderInput(context, instance, key)
644
+ : this.renderContent(context, instance, key);
645
+
646
+ return {
647
+ label: !this.labelPlacement && this.renderLabel(context, instance, key),
648
+ content: content,
649
+ helpSpacer:
650
+ this.helpSpacer && instance.components?.help ? " " : undefined,
651
+ help: !this.helpPlacement && this.renderHelp(context, instance, key),
652
+ };
653
+ }
654
+
655
+ public handleKeyDown(
656
+ e: React.KeyboardEvent,
657
+ instance: Instance,
658
+ ): boolean | void {
659
+ if (this.onKeyDown && instance.invoke("onKeyDown", e, instance) === false)
660
+ return false;
661
+
662
+ if (instance.data.tabOnEnterKey && e.keyCode === 13) {
663
+ let target = e.target;
664
+ setTimeout(() => {
665
+ if (!instance.state?.inputError)
666
+ (FocusManager as any).focusNext(target);
667
+ }, 10);
668
+ }
669
+ }
568
670
  }
569
671
 
570
672
  Field.prototype.validationMode = "tooltip";
@@ -573,7 +675,8 @@ Field.prototype.requiredText = "This field is required.";
573
675
  Field.prototype.autoFocus = false;
574
676
  Field.prototype.asterisk = false;
575
677
  Field.prototype.validatingText = "Validation is in progress...";
576
- Field.prototype.validationExceptionText = "Something went wrong during input validation. Check log for more details.";
678
+ Field.prototype.validationExceptionText =
679
+ "Something went wrong during input validation. Check log for more details.";
577
680
  Field.prototype.helpSpacer = true;
578
681
  Field.prototype.trackFocus = false; //add cxs-focus on parent element
579
682
  Field.prototype.labelPlacement = false;
@@ -590,19 +693,23 @@ Field.prototype.styled = true;
590
693
  Localization.registerPrototype("cx/widgets/Field", Field);
591
694
 
592
695
  export function getFieldTooltip(
593
- instance: FieldInstance<any>,
696
+ instance: FieldInstance<any>,
594
697
  ): [FieldInstance<any>, TooltipConfig, TooltipOptions | undefined] {
595
- let { widget, data, state } = instance;
596
-
597
- if (widget.errorTooltip && data.error && (!state || state.visited || !widget.suppressErrorsUntilVisited))
598
- return [
599
- instance,
600
- widget.errorTooltip,
601
- {
602
- data: {
603
- $error: data.error,
604
- },
605
- },
606
- ];
607
- return [instance, widget.tooltip!, undefined];
698
+ let { widget, data, state } = instance;
699
+
700
+ if (
701
+ widget.errorTooltip &&
702
+ data.error &&
703
+ (!state || state.visited || !widget.suppressErrorsUntilVisited)
704
+ )
705
+ return [
706
+ instance,
707
+ widget.errorTooltip,
708
+ {
709
+ data: {
710
+ $error: data.error,
711
+ },
712
+ },
713
+ ];
714
+ return [instance, widget.tooltip!, undefined];
608
715
  }