cx 23.5.0 → 23.5.2

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.
@@ -41,7 +41,7 @@ export class Field extends PureContainer {
41
41
  }
42
42
 
43
43
  init() {
44
- if (this.validationMode == 'tooltip' && isUndefined(this.errorTooltip)) {
44
+ if (this.validationMode == "tooltip" && isUndefined(this.errorTooltip)) {
45
45
  this.errorTooltip = {
46
46
  text: { bind: "$error" },
47
47
  mod: "error",
@@ -243,7 +243,11 @@ export class Field extends PureContainer {
243
243
  if (!data.error) {
244
244
  if (state.inputError) data.error = state.inputError;
245
245
  else if (state.validating && !empty) data.error = this.validatingText;
246
- else if (state.validationError && data.value === state.lastValidatedValue && shallowEquals(data.validationParams, state.lastValidationParams))
246
+ else if (
247
+ state.validationError &&
248
+ data.value === state.lastValidatedValue &&
249
+ shallowEquals(data.validationParams, state.lastValidationParams)
250
+ )
247
251
  data.error = state.validationError;
248
252
  else if (data.required) data.error = this.validateRequired(context, instance);
249
253
  }
@@ -253,7 +257,9 @@ export class Field extends PureContainer {
253
257
  !state.validating &&
254
258
  !data.error &&
255
259
  this.onValidate &&
256
- (!state.previouslyValidated || data.value != state.lastValidatedValue || data.validationParams != state.lastValidationParams)
260
+ (!state.previouslyValidated ||
261
+ data.value != state.lastValidatedValue ||
262
+ data.validationParams != state.lastValidationParams)
257
263
  ) {
258
264
  let result = instance.invoke("onValidate", data.value, instance, data.validationParams);
259
265
  if (isPromise(result)) {
@@ -262,14 +268,16 @@ export class Field extends PureContainer {
262
268
  validating: true,
263
269
  lastValidatedValue: data.value,
264
270
  previouslyValidated: true,
265
- lastValidationParams: data.validationParams
271
+ lastValidationParams: data.validationParams,
266
272
  });
267
273
  result
268
274
  .then((r) => {
269
275
  let { data, state } = instance;
270
- let error = data.value == state.lastValidatedValue && shallowEquals(data.validationParams, state.lastValidationParams)
271
- ? r
272
- : this.validatingText; //parameters changed, this will be revalidated
276
+ let error =
277
+ data.value == state.lastValidatedValue &&
278
+ shallowEquals(data.validationParams, state.lastValidationParams)
279
+ ? r
280
+ : this.validatingText; //parameters changed, this will be revalidated
273
281
 
274
282
  instance.setState({
275
283
  validating: false,
@@ -416,4 +424,3 @@ export function getFieldTooltip(instance) {
416
424
  ];
417
425
  return [instance, widget.tooltip];
418
426
  }
419
-
@@ -1,86 +1,88 @@
1
- import { Widget, VDOM } from "../../ui/Widget";
2
- import { HtmlElement } from "../HtmlElement";
3
- import { FocusManager } from "../../ui/FocusManager";
4
- import { isArray } from "../../util/isArray";
5
- import { coalesce } from "../../util/coalesce";
6
-
7
- export class Label extends HtmlElement {
8
- declareData() {
9
- super.declareData(...arguments, {
10
- required: undefined,
11
- disabled: undefined,
12
- htmlFor: undefined,
13
- });
14
- }
15
-
16
- prepareData(context, instance) {
17
- let { data } = instance;
18
- data.stateMods = {
19
- ...data.stateMods,
20
- disabled: data.disabled,
21
- };
22
- data._disabled = data.disabled;
23
- super.prepareData(context, instance);
24
- }
25
-
26
- explore(context, instance) {
27
- let { data } = instance;
28
-
29
- if (!data.htmlFor) data.htmlFor = context.lastFieldId;
30
-
31
- data.disabled = data.stateMods.disabled = coalesce(
32
- context.parentStrict ? context.parentDisabled : null,
33
- data._disabled,
34
- context.parentDisabled
35
- );
36
-
37
- if (instance.cache('disabled', data.disabled)) {
38
- instance.markShouldUpdate(context);
39
- this.prepareCSS(context, instance);
40
- }
41
-
42
- super.explore(context, instance);
43
- }
44
-
45
- isValidHtmlAttribute(attrName) {
46
- switch (attrName) {
47
- case "asterisk":
48
- case "required":
49
- return false;
50
- }
51
- return super.isValidHtmlAttribute(attrName);
52
- }
53
-
54
- attachProps(context, instance, props) {
55
- super.attachProps(context, instance, props);
56
-
57
- let { data } = instance;
58
-
59
- if (data.htmlFor) {
60
- props.htmlFor = data.htmlFor;
61
-
62
- if (!props.onClick)
63
- props.onClick = () => {
64
- //additional focus for LookupFields which are not input based
65
- let el = document.getElementById(instance.data.htmlFor);
66
- if (el) FocusManager.focusFirst(el);
67
- };
68
- }
69
-
70
- if (!props.id && data.htmlFor) props.id = `${data.htmlFor}-label`;
71
-
72
- if (this.asterisk && data.required) {
73
- if (!isArray(props.children)) props.children = [props.children];
74
- props.children.push(" ");
75
- props.children.push(
76
- <span key="asterisk" className={this.CSS.element(this.baseClass, "asterisk")}>
77
- *
78
- </span>
79
- );
80
- }
81
- }
82
- }
83
-
84
- Label.prototype.baseClass = "label";
85
- Label.prototype.tag = "label";
86
- Label.prototype.asterisk = false;
1
+ import { Widget, VDOM } from "../../ui/Widget";
2
+ import { HtmlElement } from "../HtmlElement";
3
+ import { FocusManager } from "../../ui/FocusManager";
4
+ import { isArray } from "../../util/isArray";
5
+ import { coalesce } from "../../util/coalesce";
6
+
7
+ export class Label extends HtmlElement {
8
+ declareData() {
9
+ super.declareData(...arguments, {
10
+ required: undefined,
11
+ disabled: undefined,
12
+ htmlFor: undefined,
13
+ });
14
+ }
15
+
16
+ prepareData(context, instance) {
17
+ let { data } = instance;
18
+ data.stateMods = {
19
+ ...data.stateMods,
20
+ disabled: data.disabled,
21
+ };
22
+ data._disabled = data.disabled;
23
+ super.prepareData(context, instance);
24
+ }
25
+
26
+ explore(context, instance) {
27
+ let { data } = instance;
28
+
29
+ if (!data.htmlFor) data.htmlFor = context.lastFieldId;
30
+
31
+ data.disabled = data.stateMods.disabled = coalesce(
32
+ context.parentStrict ? context.parentDisabled : null,
33
+ data._disabled,
34
+ context.parentDisabled
35
+ );
36
+
37
+ data.asterisk = context.parentAsterisk || this.asterisk;
38
+
39
+ if (instance.cache("disabled", data.disabled) || instance.cache("asterisk", data.asterisk)) {
40
+ instance.markShouldUpdate(context);
41
+ this.prepareCSS(context, instance);
42
+ }
43
+
44
+ super.explore(context, instance);
45
+ }
46
+
47
+ isValidHtmlAttribute(attrName) {
48
+ switch (attrName) {
49
+ case "asterisk":
50
+ case "required":
51
+ return false;
52
+ }
53
+ return super.isValidHtmlAttribute(attrName);
54
+ }
55
+
56
+ attachProps(context, instance, props) {
57
+ super.attachProps(context, instance, props);
58
+
59
+ let { data } = instance;
60
+
61
+ if (data.htmlFor) {
62
+ props.htmlFor = data.htmlFor;
63
+
64
+ if (!props.onClick)
65
+ props.onClick = () => {
66
+ //additional focus for LookupFields which are not input based
67
+ let el = document.getElementById(instance.data.htmlFor);
68
+ if (el) FocusManager.focusFirst(el);
69
+ };
70
+ }
71
+
72
+ if (!props.id && data.htmlFor) props.id = `${data.htmlFor}-label`;
73
+
74
+ if (data.required && data.asterisk) {
75
+ if (!isArray(props.children)) props.children = [props.children];
76
+ props.children.push(" ");
77
+ props.children.push(
78
+ <span key="asterisk" className={this.CSS.element(this.baseClass, "asterisk")}>
79
+ *
80
+ </span>
81
+ );
82
+ }
83
+ }
84
+ }
85
+
86
+ Label.prototype.baseClass = "label";
87
+ Label.prototype.tag = "label";
88
+ Label.prototype.asterisk = false;
@@ -33,6 +33,9 @@ export interface ValidationGroupProps extends Cx.PureContainerProps {
33
33
 
34
34
  /** Set to `true` to force children to respect disabled, readOnly, viewMode and visited flags set on the group level. */
35
35
  strict?: Cx.BooleanProp;
36
+
37
+ /** Set to `true` to add red asterisk for all required fields inside the group. */
38
+ asterisk?: boolean;
36
39
  }
37
40
 
38
41
  export class ValidationGroup extends Cx.Widget<ValidationGroupProps> {}
@@ -18,6 +18,7 @@ export class ValidationGroup extends PureContainer {
18
18
  isolated: undefined,
19
19
  visited: undefined,
20
20
  strict: undefined,
21
+ asterisk: undefined,
21
22
  });
22
23
  }
23
24
 
@@ -34,6 +35,7 @@ export class ValidationGroup extends PureContainer {
34
35
  context.push("parentViewMode", coalesce(instance.data.viewMode, context.parentViewMode));
35
36
  context.push("parentTabOnEnterKey", coalesce(instance.data.tabOnEnterKey, context.parentTabOnEnterKey));
36
37
  context.push("parentVisited", coalesce(instance.data.visited, context.parentVisited));
38
+ context.push("parentAsterisk", coalesce(instance.data.asterisk, context.parentAsterisk));
37
39
  context.push("validation", instance.validation);
38
40
 
39
41
  super.explore(context, instance);
@@ -47,6 +49,7 @@ export class ValidationGroup extends PureContainer {
47
49
  context.pop("parentViewMode");
48
50
  context.pop("parentTabOnEnterKey");
49
51
  context.pop("parentStrict");
52
+ context.pop("parentAsterisk");
50
53
 
51
54
  instance.valid = instance.validation.errors.length == 0;
52
55
  if (!instance.valid && !this.isolated && context.validation)