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.
- package/build/charts/Chart.d.ts.map +1 -1
- package/build/charts/Chart.js +5 -4
- package/build/charts/ColumnBarBase.d.ts +3 -3
- package/build/charts/ColumnBarBase.d.ts.map +1 -1
- package/build/charts/ColumnBarBase.js +1 -1
- package/build/charts/Legend.d.ts.map +1 -1
- package/build/charts/Legend.js +11 -4
- package/build/charts/Marker.d.ts +3 -3
- package/build/charts/Marker.d.ts.map +1 -1
- package/build/charts/MarkerLine.d.ts +7 -7
- package/build/charts/MarkerLine.d.ts.map +1 -1
- package/build/charts/MarkerLine.js +14 -10
- package/build/charts/PieChart.d.ts +4 -4
- package/build/charts/PieChart.d.ts.map +1 -1
- package/build/charts/PieChart.js +36 -14
- package/build/charts/PieLabel.d.ts.map +1 -1
- package/build/charts/PieLabel.js +2 -1
- package/build/charts/RangeMarker.d.ts +3 -3
- package/build/charts/RangeMarker.d.ts.map +1 -1
- package/build/charts/RangeMarker.js +1 -1
- package/build/charts/axis/TimeAxis.d.ts +3 -3
- package/build/charts/axis/TimeAxis.d.ts.map +1 -1
- package/build/charts/axis/TimeAxis.js +70 -21
- package/build/charts/helpers/ValueAtFinder.d.ts +1 -1
- package/build/charts/helpers/ValueAtFinder.d.ts.map +1 -1
- package/build/charts/helpers/ValueAtFinder.js +5 -2
- package/build/data/StructuredSelector.js +3 -4
- package/build/data/createAccessorModelProxy.d.ts +6 -11
- package/build/data/createAccessorModelProxy.d.ts.map +1 -1
- package/build/data/createAccessorModelProxy.js +1 -3
- package/build/svg/Ellipse.d.ts +5 -4
- package/build/svg/Ellipse.d.ts.map +1 -1
- package/build/svg/Ellipse.js +9 -6
- package/build/svg/Line.d.ts +1 -0
- package/build/svg/Line.d.ts.map +1 -1
- package/build/svg/Line.js +4 -1
- package/build/svg/Text.d.ts +12 -6
- package/build/svg/Text.d.ts.map +1 -1
- package/build/svg/Text.js +12 -4
- package/build/ui/Controller.d.ts +2 -0
- package/build/ui/Controller.d.ts.map +1 -1
- package/build/ui/Controller.js +3 -0
- package/build/ui/HoverSync.d.ts.map +1 -1
- package/build/ui/HoverSync.js +7 -2
- package/build/ui/Prop.d.ts +1 -1
- package/build/ui/Prop.d.ts.map +1 -1
- package/build/ui/Text.d.ts +3 -3
- package/build/ui/Text.d.ts.map +1 -1
- package/build/ui/Text.js +5 -5
- package/build/ui/adapter/GroupAdapter.d.ts.map +1 -1
- package/build/ui/adapter/GroupAdapter.js +20 -10
- package/build/ui/app/History.js +1 -1
- package/build/widgets/List.d.ts.map +1 -1
- package/build/widgets/List.js +6 -7
- package/build/widgets/drag-drop/DropZone.d.ts +3 -3
- package/build/widgets/drag-drop/DropZone.d.ts.map +1 -1
- package/build/widgets/form/Calendar.d.ts.map +1 -1
- package/build/widgets/form/Calendar.js +30 -11
- package/build/widgets/form/ColorField.d.ts.map +1 -1
- package/build/widgets/form/ColorField.js +16 -7
- package/build/widgets/form/DateTimeField.d.ts.map +1 -1
- package/build/widgets/form/DateTimeField.js +23 -10
- package/build/widgets/form/Field.d.ts +2 -0
- package/build/widgets/form/Field.d.ts.map +1 -1
- package/build/widgets/form/Field.js +11 -5
- package/build/widgets/form/LookupField.d.ts +1 -1
- package/build/widgets/form/LookupField.d.ts.map +1 -1
- package/build/widgets/form/LookupField.js +6 -6
- package/build/widgets/form/MonthField.d.ts.map +1 -1
- package/build/widgets/form/MonthField.js +15 -7
- package/build/widgets/form/MonthPicker.d.ts +1 -2
- package/build/widgets/form/MonthPicker.d.ts.map +1 -1
- package/build/widgets/form/MonthPicker.js +84 -41
- package/build/widgets/form/NumberField.d.ts +2 -0
- package/build/widgets/form/NumberField.d.ts.map +1 -1
- package/build/widgets/form/NumberField.js +45 -15
- package/build/widgets/form/TextField.d.ts +1 -9
- package/build/widgets/form/TextField.d.ts.map +1 -1
- package/build/widgets/form/TextField.js +1 -1
- package/build/widgets/grid/Grid.d.ts +2 -2
- package/build/widgets/grid/Grid.d.ts.map +1 -1
- package/build/widgets/grid/Grid.js +14 -11
- package/build/widgets/grid/Pagination.d.ts.map +1 -1
- package/build/widgets/grid/Pagination.js +4 -4
- package/build/widgets/grid/TreeNode.d.ts.map +1 -1
- package/build/widgets/grid/TreeNode.js +10 -2
- package/build/widgets/icons/folder.d.ts.map +1 -1
- package/build/widgets/icons/folder.js +1 -0
- package/build/widgets/icons/forward.d.ts.map +1 -1
- package/build/widgets/icons/forward.js +4 -3
- package/build/widgets/icons/loading.d.ts.map +1 -1
- package/build/widgets/icons/loading.js +6 -5
- package/build/widgets/icons/square.d.ts.map +1 -1
- package/build/widgets/icons/square.js +3 -3
- package/build/widgets/index.d.ts +3 -1
- package/build/widgets/index.d.ts.map +1 -1
- package/build/widgets/index.js +3 -1
- package/build/widgets/overlay/ContextMenu.d.ts.map +1 -1
- package/build/widgets/overlay/ContextMenu.js +2 -0
- package/build/widgets/overlay/Dropdown.d.ts +2 -1
- package/build/widgets/overlay/Dropdown.d.ts.map +1 -1
- package/build/widgets/overlay/Dropdown.js +75 -20
- package/build/widgets/overlay/MsgBox.d.ts +1 -0
- package/build/widgets/overlay/MsgBox.d.ts.map +1 -1
- package/build/widgets/overlay/MsgBox.js +2 -2
- package/build/widgets/overlay/Overlay.d.ts +32 -2
- package/build/widgets/overlay/Overlay.d.ts.map +1 -1
- package/build/widgets/overlay/Overlay.js +47 -16
- package/build/widgets/overlay/Toast.d.ts +1 -1
- package/build/widgets/overlay/Toast.d.ts.map +1 -1
- package/build/widgets/overlay/Toast.js +4 -1
- package/build/widgets/overlay/Tooltip.d.ts +6 -0
- package/build/widgets/overlay/Tooltip.d.ts.map +1 -1
- package/build/widgets/overlay/Tooltip.js +24 -9
- package/build/widgets/overlay/Window.d.ts.map +1 -1
- package/build/widgets/overlay/Window.js +24 -9
- package/dist/charts.css +325 -272
- package/dist/charts.js +11 -5
- package/dist/data.js +2 -2
- package/dist/manifest.js +821 -809
- package/dist/svg.css +14 -8
- package/dist/svg.js +9 -1
- package/dist/ui.js +29 -16
- package/dist/widgets.css +997 -294
- package/dist/widgets.js +319 -126
- package/package.json +1 -1
- package/src/charts/Bar.scss +13 -10
- package/src/charts/BarGraph.scss +31 -29
- package/src/charts/BubbleGraph.scss +11 -8
- package/src/charts/Chart.ts +5 -3
- package/src/charts/Column.scss +13 -10
- package/src/charts/ColumnBarBase.tsx +255 -230
- package/src/charts/ColumnGraph.scss +13 -11
- package/src/charts/Gridlines.scss +10 -8
- package/src/charts/Legend.scss +57 -50
- package/src/charts/Legend.tsx +257 -213
- package/src/charts/LegendEntry.scss +35 -29
- package/src/charts/LineGraph.scss +28 -25
- package/src/charts/Marker.scss +12 -10
- package/src/charts/Marker.tsx +3 -2
- package/src/charts/MarkerLine.scss +11 -8
- package/src/charts/MarkerLine.tsx +196 -177
- package/src/charts/PieChart.scss +12 -9
- package/src/charts/PieChart.tsx +717 -591
- package/src/charts/PieLabel.tsx +99 -81
- package/src/charts/Range.scss +11 -8
- package/src/charts/RangeMarker.tsx +204 -187
- package/src/charts/ScatterGraph.scss +12 -9
- package/src/charts/axis/Axis.scss +6 -5
- package/src/charts/axis/CategoryAxis.scss +10 -8
- package/src/charts/axis/NumericAxis.scss +9 -6
- package/src/charts/axis/TimeAxis.scss +9 -6
- package/src/charts/axis/TimeAxis.tsx +753 -637
- package/src/charts/axis/index.scss +4 -5
- package/src/charts/axis/variables.scss +4 -2
- package/src/charts/helpers/ValueAtFinder.ts +19 -5
- package/src/charts/index.scss +16 -19
- package/src/charts/maps.scss +0 -0
- package/src/charts/palette.scss +11 -31
- package/src/charts/palette.variables.scss +23 -0
- package/src/charts/variables.scss +35 -3
- package/src/data/StructuredSelector.ts +2 -2
- package/src/data/createAccessorModelProxy.ts +66 -74
- package/src/index.scss +5 -6
- package/src/maps.scss +5 -0
- package/src/svg/Ellipse.tsx +62 -55
- package/src/svg/Line.tsx +57 -42
- package/src/svg/Svg.scss +6 -6
- package/src/svg/Text.scss +19 -0
- package/src/svg/Text.tsx +172 -116
- package/src/svg/index.scss +3 -2
- package/src/svg/maps.scss +0 -0
- package/src/svg/variables.scss +0 -0
- package/src/ui/Container.spec.ts +59 -0
- package/src/ui/Controller.spec.tsx +30 -0
- package/src/ui/Controller.ts +5 -0
- package/src/ui/HoverSync.tsx +179 -147
- package/src/ui/Prop.ts +1 -1
- package/src/ui/Text.ts +12 -9
- package/src/ui/adapter/GroupAdapter.spec.ts +42 -0
- package/src/ui/adapter/GroupAdapter.ts +25 -14
- package/src/ui/app/History.ts +1 -1
- package/src/ui/index.scss +1 -1
- package/src/ui/layout/LabelsLeftLayout.scss +5 -7
- package/src/ui/layout/LabelsTopLayout.scss +4 -6
- package/src/ui/layout/index.scss +2 -3
- package/src/ui/maps.scss +0 -0
- package/src/ui/variables.scss +1 -2
- package/src/util/index.scss +4 -2
- package/src/util/maps.scss +1 -0
- package/src/util/scss/besm.scss +15 -0
- package/src/util/scss/calc.scss +103 -11
- package/src/util/scss/defaults.scss +24 -0
- package/src/util/scss/elements.scss +78 -0
- package/src/util/scss/global.scss +15 -0
- package/src/util/scss/include.scss +17 -9
- package/src/util/scss/index.scss +1 -9
- package/src/util/scss/maps.scss +2 -0
- package/src/util/scss/pad-size.scss +9 -0
- package/src/util/scss/padding.scss +6 -0
- package/src/util/scss/screen-size.scss +5 -0
- package/src/util/scss/variables.scss +6 -0
- package/src/util/variables.scss +1 -0
- package/src/variables.scss +5 -217
- package/src/widgets/Button.maps.scss +103 -0
- package/src/widgets/Button.scss +33 -9
- package/src/widgets/Button.variables.scss +8 -104
- package/src/widgets/CxCredit.scss +2 -0
- package/src/widgets/FlexBox.scss +16 -11
- package/src/widgets/Heading.scss +6 -0
- package/src/widgets/HighlightedSearchText.scss +8 -1
- package/src/widgets/Icon.scss +6 -0
- package/src/widgets/List.scss +7 -0
- package/src/widgets/List.tsx +6 -7
- package/src/widgets/ProgressBar.scss +9 -0
- package/src/widgets/Resizer.scss +9 -7
- package/src/widgets/Section.scss +53 -56
- package/src/widgets/animations.scss +4 -2
- package/src/widgets/box.scss +47 -0
- package/src/widgets/drag-drop/DragClone.scss +12 -4
- package/src/widgets/drag-drop/DragHandle.scss +12 -6
- package/src/widgets/drag-drop/DragSource.scss +12 -6
- package/src/widgets/drag-drop/DropZone.scss +9 -0
- package/src/widgets/drag-drop/DropZone.tsx +3 -3
- package/src/widgets/drag-drop/index.scss +4 -4
- package/src/widgets/drag-drop/maps.scss +7 -0
- package/src/widgets/drag-drop/variables.scss +8 -5
- package/src/widgets/form/Calendar.maps.scss +54 -0
- package/src/widgets/form/Calendar.scss +49 -11
- package/src/widgets/form/Calendar.tsx +755 -653
- package/src/widgets/form/Calendar.variables.scss +3 -46
- package/src/widgets/form/Checkbox.maps.scss +34 -0
- package/src/widgets/form/Checkbox.scss +14 -3
- package/src/widgets/form/Checkbox.variables.scss +4 -36
- package/src/widgets/form/ColorField.scss +21 -2
- package/src/widgets/form/ColorField.tsx +485 -431
- package/src/widgets/form/ColorPicker.maps.scss +21 -0
- package/src/widgets/form/ColorPicker.scss +26 -9
- package/src/widgets/form/ColorPicker.variables.scss +3 -16
- package/src/widgets/form/DateTimeField.scss +54 -21
- package/src/widgets/form/DateTimeField.tsx +697 -615
- package/src/widgets/form/DateTimePicker.scss +14 -4
- package/src/widgets/form/Field.maps.scss +122 -0
- package/src/widgets/form/Field.scss +54 -18
- package/src/widgets/form/Field.tsx +611 -504
- package/src/widgets/form/Field.variables.scss +46 -0
- package/src/widgets/form/HelpText.scss +8 -5
- package/src/widgets/form/Label.scss +10 -3
- package/src/widgets/form/LookupField.maps.scss +26 -0
- package/src/widgets/form/LookupField.scss +54 -24
- package/src/widgets/form/LookupField.tsx +25 -21
- package/src/widgets/form/MonthField.scss +48 -26
- package/src/widgets/form/MonthField.tsx +645 -567
- package/src/widgets/form/MonthPicker.maps.scss +50 -0
- package/src/widgets/form/MonthPicker.scss +44 -35
- package/src/widgets/form/MonthPicker.tsx +954 -724
- package/src/widgets/form/MonthPicker.variables.scss +24 -0
- package/src/widgets/form/NumberField.scss +19 -2
- package/src/widgets/form/NumberField.tsx +576 -466
- package/src/widgets/form/Radio.maps.scss +36 -0
- package/src/widgets/form/Radio.scss +12 -2
- package/src/widgets/form/Radio.variables.scss +3 -42
- package/src/widgets/form/Select.scss +25 -9
- package/src/widgets/form/Slider.scss +23 -14
- package/src/widgets/form/Switch.scss +18 -8
- package/src/widgets/form/TextArea.scss +14 -1
- package/src/widgets/form/TextField.scss +24 -3
- package/src/widgets/form/TextField.tsx +9 -21
- package/src/widgets/form/UploadButton.scss +14 -6
- package/src/widgets/form/ValidationError.scss +10 -6
- package/src/widgets/form/Wheel.scss +14 -4
- package/src/widgets/form/index.scss +22 -24
- package/src/widgets/form/maps.scss +81 -0
- package/src/widgets/form/variables.scss +111 -355
- package/src/widgets/grid/Grid.scss +19 -2
- package/src/widgets/grid/Grid.spec.ts +42 -0
- package/src/widgets/grid/Grid.tsx +18 -13
- package/src/widgets/grid/Pagination.scss +11 -2
- package/src/widgets/grid/Pagination.tsx +110 -102
- package/src/widgets/grid/TreeNode.scss +25 -8
- package/src/widgets/grid/TreeNode.tsx +127 -116
- package/src/widgets/grid/index.scss +3 -4
- package/src/widgets/grid/maps.scss +110 -0
- package/src/widgets/grid/variables.scss +48 -137
- package/src/widgets/icons/folder.tsx +1 -2
- package/src/widgets/icons/forward.tsx +23 -20
- package/src/widgets/icons/loading.tsx +22 -19
- package/src/widgets/icons/square.tsx +20 -17
- package/src/widgets/index.scss +16 -16
- package/src/widgets/index.ts +63 -58
- package/src/widgets/lists.scss +42 -0
- package/src/widgets/maps.scss +139 -0
- package/src/widgets/nav/Link.scss +14 -1
- package/src/widgets/nav/Menu.scss +13 -7
- package/src/widgets/nav/Menu.variables.scss +1 -12
- package/src/widgets/nav/MenuItem.scss +21 -6
- package/src/widgets/nav/Scroller.scss +11 -2
- package/src/widgets/nav/Tab.maps.scss +78 -0
- package/src/widgets/nav/Tab.scss +12 -6
- package/src/widgets/nav/Tab.variables.scss +7 -76
- package/src/widgets/nav/cover.scss +6 -4
- package/src/widgets/nav/index.scss +6 -6
- package/src/widgets/nav/maps.scss +32 -0
- package/src/widgets/nav/variables.scss +4 -11
- package/src/widgets/overlay/ContextMenu.ts +3 -0
- package/src/widgets/overlay/Dropdown.scss +47 -16
- package/src/widgets/overlay/Dropdown.tsx +851 -676
- package/src/widgets/overlay/MsgBox.tsx +125 -111
- package/src/widgets/overlay/Overlay.scss +60 -40
- package/src/widgets/overlay/Overlay.tsx +948 -800
- package/src/widgets/overlay/Toast.scss +42 -34
- package/src/widgets/overlay/Toast.ts +11 -1
- package/src/widgets/overlay/Tooltip.scss +27 -96
- package/src/widgets/overlay/Tooltip.tsx +376 -309
- package/src/widgets/overlay/Window.maps.scss +51 -0
- package/src/widgets/overlay/Window.scss +17 -17
- package/src/widgets/overlay/Window.tsx +291 -236
- package/src/widgets/overlay/Window.variables.scss +2 -43
- package/src/widgets/overlay/index.d.ts +11 -11
- package/src/widgets/overlay/index.scss +6 -15
- package/src/widgets/overlay/maps.scss +44 -0
- package/src/widgets/overlay/variables.scss +11 -42
- package/src/widgets/variables.scss +33 -117
- package/src/global.scss +0 -14
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
28
|
-
|
|
40
|
+
/** Field label. For advanced use cases. */
|
|
41
|
+
label?: StringProp | Config;
|
|
29
42
|
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
/** Set to `material` to use custom label placement instruction. Used in Material theme to implement animated labels. */
|
|
44
|
+
labelPlacement?: "material";
|
|
32
45
|
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
49
|
+
/** Either `view` or `edit` (default). In `view` mode, the field is displayed as plain text. */
|
|
50
|
+
mode?: Prop<"view" | "edit">;
|
|
38
51
|
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
/** Set to `true` to switch to widget view mode. Same as `mode="view"`. Default is false. */
|
|
53
|
+
viewMode?: BooleanProp;
|
|
41
54
|
|
|
42
|
-
|
|
55
|
+
id?: Prop<string | number>;
|
|
43
56
|
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
/** Used for validation. If error evaluates to non-null, the field is marked in red. */
|
|
58
|
+
error?: StringProp;
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
/** Style object applied to the input element. Used for setting visual elements, such as borders and backgrounds. */
|
|
61
|
+
inputStyle?: StyleProp;
|
|
49
62
|
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
54
|
-
|
|
66
|
+
/** Additional attributes that should be rendered on the input element. E.g. inputAttrs={{ autoComplete: "off" }}. */
|
|
67
|
+
inputAttrs?: Config;
|
|
55
68
|
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
/** Text to be rendered in view mode when the field is empty. */
|
|
70
|
+
emptyText?: StringProp;
|
|
58
71
|
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
63
|
-
|
|
75
|
+
/** Set to `true` to automatically focus the field, after it renders for the first time. */
|
|
76
|
+
autoFocus?: BooleanProp;
|
|
64
77
|
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
|
|
81
|
+
/** Defaults to `false`. Set to `true` to disable the field. */
|
|
82
|
+
disabled?: BooleanProp;
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
/** The opposite of `disabled`. */
|
|
85
|
+
enabled?: BooleanProp;
|
|
73
86
|
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
/** Defaults to `false`. Used to make the field required. */
|
|
88
|
+
required?: BooleanProp;
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
/** Used to indicate that required fields should not be marked as invalid before the user visits them. */
|
|
91
|
+
suppressErrorsUntilVisited?: boolean;
|
|
79
92
|
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
/** Error message used to indicate that field is required. */
|
|
94
|
+
requiredText?: string;
|
|
82
95
|
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
/** Append asterisk to the label to indicate a required field. */
|
|
97
|
+
asterisk?: BooleanProp;
|
|
85
98
|
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
/** Text displayed to the user to indicate that server-side validation is in progress. */
|
|
100
|
+
validatingText?: string;
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
/** Text displayed to the user to indicate that server-side validation has thrown an exception. */
|
|
103
|
+
validationExceptionText?: string;
|
|
91
104
|
|
|
92
|
-
|
|
93
|
-
|
|
105
|
+
/** Configuration of the tooltip used to indicate validation errors. */
|
|
106
|
+
errorTooltip?: Config;
|
|
94
107
|
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
/** Tooltip configuration. */
|
|
109
|
+
tooltip?: StringProp | StructuredProp;
|
|
97
110
|
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
/** Indicates that `help` should be separated from the input with a whitespace. Default is `true`. */
|
|
112
|
+
helpSpacer?: boolean;
|
|
100
113
|
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
117
|
+
/** Custom tab index */
|
|
118
|
+
tabIndex?: StringProp;
|
|
106
119
|
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
/** Additional content to be displayed next to the field. */
|
|
121
|
+
help?: string | Config;
|
|
109
122
|
|
|
110
|
-
|
|
123
|
+
/** Validation parameters to be passed to the validation function. */
|
|
124
|
+
validationParams?: Config;
|
|
111
125
|
|
|
112
|
-
|
|
113
|
-
|
|
126
|
+
onValidationException?:
|
|
127
|
+
| string
|
|
128
|
+
| ((error: unknown, instance: FieldInstance) => void);
|
|
114
129
|
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
/** Value to be set in the store if the field is empty. Default value is null. */
|
|
131
|
+
emptyValue?: unknown;
|
|
117
132
|
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
124
|
-
|
|
141
|
+
extends Instance<F>
|
|
142
|
+
implements TooltipParentInstance
|
|
125
143
|
{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
137
|
-
|
|
154
|
+
Config extends FieldConfig = FieldConfig,
|
|
155
|
+
InstanceType extends FieldInstance<any> = FieldInstance<any>,
|
|
138
156
|
> extends PureContainerBase<Config, InstanceType> {
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
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
|
-
if (!data.error
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
434
|
-
|
|
435
|
-
previouslyValidated: true,
|
|
436
|
-
lastValidationParams: data.validationParams,
|
|
500
|
+
validating: false,
|
|
501
|
+
validationError: error,
|
|
437
502
|
});
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
instance
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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> </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 =
|
|
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
|
-
|
|
696
|
+
instance: FieldInstance<any>,
|
|
594
697
|
): [FieldInstance<any>, TooltipConfig, TooltipOptions | undefined] {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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
|
}
|