@ember-eui/validated-form 16.0.4 → 16.1.0
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/declarations/-private/lazy-component.d.ts +20 -0
- package/declarations/-private/lazy-component.d.ts.map +1 -0
- package/declarations/-private/reveal-first-invalid.d.ts +12 -0
- package/declarations/-private/reveal-first-invalid.d.ts.map +1 -0
- package/declarations/components/validated-form/field-base.d.ts +17 -1
- package/declarations/components/validated-form/field-base.d.ts.map +1 -1
- package/declarations/components/validated-form/field-combo-box.d.ts +2 -0
- package/declarations/components/validated-form/field-combo-box.d.ts.map +1 -1
- package/declarations/components/validated-form/field-dual-range-slider.d.ts +2 -0
- package/declarations/components/validated-form/field-dual-range-slider.d.ts.map +1 -1
- package/declarations/components/validated-form/field-markdown-editor.d.ts +10 -1
- package/declarations/components/validated-form/field-markdown-editor.d.ts.map +1 -1
- package/declarations/components/validated-form/field-range-slider.d.ts +2 -0
- package/declarations/components/validated-form/field-range-slider.d.ts.map +1 -1
- package/declarations/components/validated-form.d.ts +12 -1
- package/declarations/components/validated-form.d.ts.map +1 -1
- package/dist/-private/lazy-component.js +46 -0
- package/dist/-private/lazy-component.js.map +1 -0
- package/dist/-private/reveal-first-invalid.js +35 -0
- package/dist/-private/reveal-first-invalid.js.map +1 -0
- package/dist/components/validated-form/field-base.js +66 -18
- package/dist/components/validated-form/field-base.js.map +1 -1
- package/dist/components/validated-form/field-combo-box.js +7 -3
- package/dist/components/validated-form/field-combo-box.js.map +1 -1
- package/dist/components/validated-form/field-dual-range-slider.js +8 -4
- package/dist/components/validated-form/field-dual-range-slider.js.map +1 -1
- package/dist/components/validated-form/field-markdown-editor.js +10 -4
- package/dist/components/validated-form/field-markdown-editor.js.map +1 -1
- package/dist/components/validated-form/field-range-slider.js +8 -4
- package/dist/components/validated-form/field-range-slider.js.map +1 -1
- package/dist/components/validated-form.js +74 -18
- package/dist/components/validated-form.js.map +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A component imported the first time it is read, so the fields that render
|
|
3
|
+
* a heavy control (combo box, ranges, markdown editor) do not bring it into
|
|
4
|
+
* the bundle of every app that imports the form. `component` is `undefined`
|
|
5
|
+
* until the import resolves; it is tracked, so the field renders then, and
|
|
6
|
+
* every later read, from any field, has it at once. The import is a test
|
|
7
|
+
* waiter: `settled()` waits for it.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LazyComponent<T> {
|
|
10
|
+
private importComponent;
|
|
11
|
+
private loaded?;
|
|
12
|
+
private loading?;
|
|
13
|
+
constructor(importComponent: () => Promise<{
|
|
14
|
+
default: T;
|
|
15
|
+
}>);
|
|
16
|
+
get component(): T | undefined;
|
|
17
|
+
/** Imports the component now, e.g. before showing a form that uses it. */
|
|
18
|
+
load(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=lazy-component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-component.d.ts","sourceRoot":"","sources":["../../src/-private/lazy-component.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,qBAAa,aAAa,CAAC,CAAC;IAId,OAAO,CAAC,eAAe;IAH1B,OAAO,CAAC,MAAM,CAAC,CAAI;IAC5B,OAAO,CAAC,OAAO,CAAC,CAAgB;gBAEZ,eAAe,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,CAAC;IAElE,IAAI,SAAS,IAAI,CAAC,GAAG,SAAS,CAI7B;IAED,0EAA0E;IAC1E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAoBtB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrolls the first invalid field of `form` into view and focuses its
|
|
3
|
+
* control, as the browser does when its own constraint validation blocks a
|
|
4
|
+
* submit. The first match in document order is a row's label or its
|
|
5
|
+
* control; the whole row is scrolled to, and the first control in it that
|
|
6
|
+
* can take focus is focused. Custom fields that report their validity
|
|
7
|
+
* through a hidden stand-in input thus get their row scrolled to and their
|
|
8
|
+
* visible control focused, never the stand-in (which the browser cannot
|
|
9
|
+
* focus).
|
|
10
|
+
*/
|
|
11
|
+
export declare function revealFirstInvalid(form: HTMLElement): void;
|
|
12
|
+
//# sourceMappingURL=reveal-first-invalid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reveal-first-invalid.d.ts","sourceRoot":"","sources":["../../src/-private/reveal-first-invalid.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAW1D"}
|
|
@@ -55,8 +55,23 @@ export default class ValidatedFormFieldBase<T extends FieldBaseSignature = Field
|
|
|
55
55
|
validationProperty: string;
|
|
56
56
|
lastIsValid?: boolean;
|
|
57
57
|
lastIsTouched?: boolean;
|
|
58
|
-
_validationErrorMessages: null | string[];
|
|
59
58
|
isTouched: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The messages of `@validations` and `@customValidations` for the current
|
|
61
|
+
* value. Derived, so a field renders once with its messages on insert and
|
|
62
|
+
* once per value change (they used to be stored after each render, which
|
|
63
|
+
* rendered every field twice).
|
|
64
|
+
*/
|
|
65
|
+
get derivedValidationErrorMessages(): string[];
|
|
66
|
+
private get derivedValidation();
|
|
67
|
+
private revision;
|
|
68
|
+
/**
|
|
69
|
+
* An assignment (subclasses used to store the messages here) shows until
|
|
70
|
+
* the value or the validations change.
|
|
71
|
+
*/
|
|
72
|
+
private _assignedMessages?;
|
|
73
|
+
get _validationErrorMessages(): null | string[];
|
|
74
|
+
set _validationErrorMessages(messages: null | string[]);
|
|
60
75
|
formRowElement: HTMLElement | null;
|
|
61
76
|
get validations(): {};
|
|
62
77
|
get hasErrorMessages(): boolean;
|
|
@@ -75,6 +90,7 @@ export default class ValidatedFormFieldBase<T extends FieldBaseSignature = Field
|
|
|
75
90
|
constructor(owner: Owner, args: T['Args']);
|
|
76
91
|
setValidationMessages(ele?: HTMLElement): void;
|
|
77
92
|
didUpdateValue(): void;
|
|
93
|
+
private notifyValidityChangeIfAlive;
|
|
78
94
|
notifyValidityChange(): void;
|
|
79
95
|
setIsTouched(val: boolean): void;
|
|
80
96
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-base.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-base.gts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"field-base.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-base.gts"],"names":[],"mappings":"AAkRA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAI3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAOtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,aAAa;IACnD,IAAI,EAAE;QACJ,gFAAgF;QAChF,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,mDAAmD;QACnD,KAAK,EAAE,GAAG,CAAC;QACX,uBAAuB;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,+EAA+E;QAC/E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,gFAAgF;QAChF,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;QAChB;;;;;WAKG;QACH,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB;;;;WAIG;QACH,iBAAiB,CAAC,EAAE;YAClB,UAAU,CACR,KAAK,EAAE,GAAG,EACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,GAAG,MAAM,GAAG;gBAAE,IAAI,CAAC,EAAE,MAAM,CAAC;gBAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;aAAE,CAAC;YAC3E,M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,mBAAmB,YAEtB;IAED,IAAI,oBAAoB,YAEvB;IAED,IAAI,oBAAoB,CAAC,KAAK,SAAA,EAE7B;IAED,IAAI,iBAAiB,IAAI,WAAW,CAClC,kBAAkB,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAChD,CAEA;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,QAAQ,OAEX;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,IAAI,OAAO,IAAI,GAAG,EAAE,CAEnB;IAED,IAAI,uBAAuB,oBAmB1B;gBAEW,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IAOzC,qBAAqB,CAAC,GAAG,CAAC,EAAE,WAAW;IAUvC,cAAc;IAWd,OAAO,CAAC,2BAA2B;IAOnC,oBAAoB;IAKpB,YAAY,CAAC,GAAG,EAAE,OAAO;IAKzB;;;;;;;OAOG;IAEH,YAAY,CAAC,CAAC,EAAE,KAAK;IAOrB,WAAW,IAAI,IAAI;CAepB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ValidatedFormFieldBase from './field-base';
|
|
2
2
|
import type { FieldBaseSignature } from './field-base';
|
|
3
|
+
import type EuiComboBox from '@ember-eui/core/components/eui-combo-box';
|
|
3
4
|
import type { EuiComboBoxSignature } from '@ember-eui/core/components/eui-combo-box';
|
|
4
5
|
import type { EuiFormRowSignature } from '@ember-eui/core/components/eui-form-row';
|
|
5
6
|
/**
|
|
@@ -37,5 +38,6 @@ export interface FieldComboBoxSignature {
|
|
|
37
38
|
export default class ValidatedFormFieldComboBox extends ValidatedFormFieldBase<FieldComboBoxSignature> {
|
|
38
39
|
validationProperty: string;
|
|
39
40
|
handleChange(options: any[]): void;
|
|
41
|
+
get EuiComboBox(): typeof EuiComboBox | undefined;
|
|
40
42
|
}
|
|
41
43
|
//# sourceMappingURL=field-combo-box.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-combo-box.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-combo-box.gts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"field-combo-box.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-combo-box.gts"],"names":[],"mappings":"AAqNA,OAAO,sBAAsB,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,WAAW,MAAM,0CAA0C,CAAC;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAEnF;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACzC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAC9B,mBAAmB,CAAC,MAAM,CAAC,GAC3B,oBAAoB,CAAC,MAAM,CAAC,GAAG;QAC7B,kCAAkC;QAClC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,+BAA+B;QAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,qCAAqC;QACrC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,uCAAuC;QACvC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,4DAA4D;QAC5D,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,wCAAwC;QACxC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QACpC,wBAAwB;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,oCAAoC;QACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;QAClD,4BAA4B;QAC5B,eAAe,CAAC,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;KACnE,CAAC;IACJ,MAAM,EAAE;QACN,KAAK,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9C,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC;QACpD,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;KACpD,CAAC;CACH;AAOD,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,sBAAsB,CAAC,sBAAsB,CAAC;IACpG,kBAAkB,SAA0B;IAI5C,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE;IAK3B,IAAI,WAAW,mCAEd;CAmFF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ValidatedFormFieldBase from './field-base';
|
|
2
2
|
import type { FieldBaseSignature } from './field-base';
|
|
3
|
+
import type EuiDualRange from '@ember-eui/core/components/eui-dual-range';
|
|
3
4
|
import type { EuiDualRangeSignature, ValueMember } from '@ember-eui/core/components/eui-dual-range';
|
|
4
5
|
import type { EuiFormRowSignature } from '@ember-eui/core/components/eui-form-row';
|
|
5
6
|
/**
|
|
@@ -45,5 +46,6 @@ export interface FieldDualRangeSliderSignature {
|
|
|
45
46
|
}
|
|
46
47
|
export default class ValidatedFormFieldRangeSlider extends ValidatedFormFieldBase<FieldDualRangeSliderSignature> {
|
|
47
48
|
handleChange(e: [ValueMember, ValueMember], _isValid: boolean, _event: Event): void;
|
|
49
|
+
get EuiDualRange(): typeof EuiDualRange | undefined;
|
|
48
50
|
}
|
|
49
51
|
//# sourceMappingURL=field-dual-range-slider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-dual-range-slider.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-dual-range-slider.gts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"field-dual-range-slider.d.ts","sourceRoot":"","sources":["../../../src/components/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KAAK,EAAE,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;QACzD,OAAO,EAAE,CAAC,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACzD,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QACjD,MAAM,EAAE,CAAC,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;KAClD,CAAC;CACH;AAOD,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,sBAAsB,CAAC,6BAA6B,CAAC;IAG9G,YAAY,CACV,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,EAC7B,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,KAAK;IASf,IAAI,YAAY,oCAEf;CA6GF"}
|
|
@@ -24,7 +24,10 @@ export interface FieldMarkdownEditorSignature {
|
|
|
24
24
|
onChange?: (value: string) => void;
|
|
25
25
|
/** Placeholder text. */
|
|
26
26
|
placeholder?: string;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Renders this editor instead of EuiMarkdownEditor (which is then
|
|
29
|
+
* never loaded), with the same args.
|
|
30
|
+
*/
|
|
28
31
|
editorComponent?: ComponentLike;
|
|
29
32
|
};
|
|
30
33
|
Blocks: {
|
|
@@ -32,7 +35,13 @@ export interface FieldMarkdownEditorSignature {
|
|
|
32
35
|
helpText: [...EuiFormRowSignature['Blocks']['helpText']];
|
|
33
36
|
};
|
|
34
37
|
}
|
|
38
|
+
type MarkdownEditorLike = ComponentLike<{
|
|
39
|
+
Element: FieldMarkdownEditorSignature['Element'];
|
|
40
|
+
Args: Record<string, any>;
|
|
41
|
+
}>;
|
|
35
42
|
export default class ValidatedFormFieldMarkdownEditor extends ValidatedFormFieldBase<FieldMarkdownEditorSignature> {
|
|
36
43
|
handleChange(str: string): void;
|
|
44
|
+
get MarkdownEditor(): MarkdownEditorLike | undefined;
|
|
37
45
|
}
|
|
46
|
+
export {};
|
|
38
47
|
//# sourceMappingURL=field-markdown-editor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-markdown-editor.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-markdown-editor.gts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"field-markdown-editor.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-markdown-editor.gts"],"names":[],"mappings":"AAsJA,OAAO,sBAAsB,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAEnF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AACjG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE,0BAA0B,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAC9B,mBAAmB,CAAC,MAAM,CAAC,GAC3B,0BAA0B,CAAC,MAAM,CAAC,GAAG;QACnC,kCAAkC;QAClC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,+BAA+B;QAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,qCAAqC;QACrC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,uCAAuC;QACvC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,qCAAqC;QACrC,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,qCAAqC;QACrC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QACnC,wBAAwB;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB;;;WAGG;QACH,eAAe,CAAC,EAAE,aAAa,CAAC;KACjC,CAAC;IACJ,MAAM,EAAE;QACN,KAAK,EAAE,CAAC,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QACnD,QAAQ,EAAE,CAAC,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;KAC1D,CAAC;CACH;AAED,KAAK,kBAAkB,GAAG,aAAa,CAAC;IACtC,OAAO,EAAE,4BAA4B,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B,CAAC,CAAC;AAOH,MAAM,CAAC,OAAO,OAAO,gCAAiC,SAAQ,sBAAsB,CAAC,4BAA4B,CAAC;IAGhH,YAAY,CAAC,GAAG,EAAE,MAAM;IAOxB,IAAI,cAAc,IAAI,kBAAkB,GAAG,SAAS,CAInD;CAyFF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ValidatedFormFieldBase from './field-base';
|
|
2
2
|
import type { FieldBaseSignature } from './field-base';
|
|
3
3
|
import type { EuiFormRowSignature } from '@ember-eui/core/components/eui-form-row';
|
|
4
|
+
import type EuiRange from '@ember-eui/core/components/eui-range';
|
|
4
5
|
import type { EuiRangeSignature } from '@ember-eui/core/components/eui-range';
|
|
5
6
|
/**
|
|
6
7
|
* A validated range slider in an EuiFormRow. Takes FieldBase's, EuiFormRow's and
|
|
@@ -35,5 +36,6 @@ export interface FieldRangeSliderSignature {
|
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
export default class ValidatedFormFieldRangeSlider extends ValidatedFormFieldBase<FieldRangeSliderSignature> {
|
|
39
|
+
get EuiRange(): typeof EuiRange | undefined;
|
|
38
40
|
}
|
|
39
41
|
//# sourceMappingURL=field-range-slider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-range-slider.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-range-slider.gts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"field-range-slider.d.ts","sourceRoot":"","sources":["../../../src/components/validated-form/field-range-slider.gts"],"names":[],"mappings":"AAuKA,OAAO,sBAAsB,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,KAAK,QAAQ,MAAM,sCAAsC,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAE9E;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACtC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAC9B,mBAAmB,CAAC,MAAM,CAAC,GAC3B,iBAAiB,CAAC,MAAM,CAAC,GAAG;QAC1B,kCAAkC;QAClC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,+BAA+B;QAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,qCAAqC;QACrC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,uCAAuC;QACvC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,qCAAqC;QACrC,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,iDAAiD;QACjD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACpC,CAAC;IACJ,MAAM,EAAE;QACN,KAAK,EAAE,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;QACzD,OAAO,EAAE,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACrD,GAAG,EAAE,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7C,YAAY,EAAE,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QAC/D,KAAK,EAAE,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QACjD,WAAW,EAAE,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;QAC7D,MAAM,EAAE,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACnD,GAAG,EAAE,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;KAC9C,CAAC;CACH;AAOD,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,sBAAsB,CAAC,yBAAyB,CAAC;IAC1G,IAAI,QAAQ,gCAEX;CAgIF"}
|
|
@@ -28,6 +28,11 @@ export interface ValidatedFormSignature {
|
|
|
28
28
|
removeChild?: (child: ValidatedFormChild) => void;
|
|
29
29
|
/** Called on submit while a field is invalid (all fields show their errors). */
|
|
30
30
|
onInvalid?: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* On a submit with errors, after `@onInvalid`, scroll to the first
|
|
33
|
+
* invalid field and focus its control. Defaults to `true`.
|
|
34
|
+
*/
|
|
35
|
+
revealFirstInvalid?: boolean;
|
|
31
36
|
/**
|
|
32
37
|
* Called on submit when every field is valid. If it returns a promise
|
|
33
38
|
* that rejects, the fields are marked touched again.
|
|
@@ -105,8 +110,13 @@ export default class ValidatedFormComponent extends Component<ValidatedFormSigna
|
|
|
105
110
|
willDestroy(): void;
|
|
106
111
|
get isValid(): boolean;
|
|
107
112
|
get isInvalidAndTouched(): boolean;
|
|
113
|
+
private children;
|
|
114
|
+
private invalidChildren;
|
|
115
|
+
private touchedChildren;
|
|
108
116
|
addChild(child: ValidatedFormChild): void;
|
|
109
117
|
removeChild(child: ValidatedFormChild): void;
|
|
118
|
+
private updateChild;
|
|
119
|
+
private updateChildren;
|
|
110
120
|
handleSubmit(e: Event): Promise<void>;
|
|
111
121
|
setIsTouched(isTouched: boolean): void;
|
|
112
122
|
handleReset(e: Event): void;
|
|
@@ -117,7 +127,8 @@ export default class ValidatedFormComponent extends Component<ValidatedFormSigna
|
|
|
117
127
|
getIsTouched(): boolean;
|
|
118
128
|
triggerValidityChange(): void;
|
|
119
129
|
setNewValidity(): void;
|
|
120
|
-
|
|
130
|
+
private flushValidity;
|
|
131
|
+
onChildValidityChange(change?: unknown): void;
|
|
121
132
|
onFocusOut(e: FocusEvent): void;
|
|
122
133
|
get theme(): {
|
|
123
134
|
FieldNestedForm: import("@glint/template").ComponentLike<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validated-form.d.ts","sourceRoot":"","sources":["../../src/components/validated-form.gts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validated-form.d.ts","sourceRoot":"","sources":["../../src/components/validated-form.gts"],"names":[],"mappings":"AA0jBA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAQjC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAMtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,SAAS,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,sBAAsB,CAAC;AAkBpE;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAA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C,cAAc;IAKd,UAAU;IAIV,YAAY;IAIZ,qBAAqB;IAYrB,cAAc;IAId,OAAO,CAAC,aAAa;IA+BrB,qBAAqB,CAAC,MAAM,CAAC,EAAE,OAAO;IAgBtC,UAAU,CAAC,CAAC,EAAE,UAAU;IAyBxB,IAAI,KAAK;;;;;;;;;;;;;;;MAIR;CAwDF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { tracked } from '@glimmer/tracking';
|
|
2
|
+
import { buildWaiter } from '@ember/test-waiters';
|
|
3
|
+
import { g, i } from 'decorator-transforms/runtime-esm';
|
|
4
|
+
|
|
5
|
+
const waiter = buildWaiter('@ember-eui/validated-form:lazy-component');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A component imported the first time it is read, so the fields that render
|
|
9
|
+
* a heavy control (combo box, ranges, markdown editor) do not bring it into
|
|
10
|
+
* the bundle of every app that imports the form. `component` is `undefined`
|
|
11
|
+
* until the import resolves; it is tracked, so the field renders then, and
|
|
12
|
+
* every later read, from any field, has it at once. The import is a test
|
|
13
|
+
* waiter: `settled()` waits for it.
|
|
14
|
+
*/
|
|
15
|
+
class LazyComponent {
|
|
16
|
+
static {
|
|
17
|
+
g(this.prototype, "loaded", [tracked]);
|
|
18
|
+
}
|
|
19
|
+
#loaded = (i(this, "loaded"), void 0);
|
|
20
|
+
loading;
|
|
21
|
+
constructor(importComponent) {
|
|
22
|
+
this.importComponent = importComponent;
|
|
23
|
+
}
|
|
24
|
+
get component() {
|
|
25
|
+
void this.load();
|
|
26
|
+
return this.loaded;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Imports the component now, e.g. before showing a form that uses it. */
|
|
30
|
+
load() {
|
|
31
|
+
if (!this.loading) {
|
|
32
|
+
const token = waiter.beginAsync();
|
|
33
|
+
this.loading = this.importComponent().then(module => {
|
|
34
|
+
this.loaded = module.default;
|
|
35
|
+
}, error => {
|
|
36
|
+
// let a later render try again
|
|
37
|
+
this.loading = undefined;
|
|
38
|
+
throw error;
|
|
39
|
+
}).finally(() => waiter.endAsync(token));
|
|
40
|
+
}
|
|
41
|
+
return this.loading;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { LazyComponent };
|
|
46
|
+
//# sourceMappingURL=lazy-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-component.js","sources":["../../src/-private/lazy-component.ts"],"sourcesContent":["import { tracked } from '@glimmer/tracking';\nimport { buildWaiter } from '@ember/test-waiters';\n\nconst waiter = buildWaiter('@ember-eui/validated-form:lazy-component');\n\n/**\n * A component imported the first time it is read, so the fields that render\n * a heavy control (combo box, ranges, markdown editor) do not bring it into\n * the bundle of every app that imports the form. `component` is `undefined`\n * until the import resolves; it is tracked, so the field renders then, and\n * every later read, from any field, has it at once. The import is a test\n * waiter: `settled()` waits for it.\n */\nexport class LazyComponent<T> {\n @tracked private loaded?: T;\n private loading?: Promise<void>;\n\n constructor(private importComponent: () => Promise<{ default: T }>) {}\n\n get component(): T | undefined {\n void this.load();\n\n return this.loaded;\n }\n\n /** Imports the component now, e.g. before showing a form that uses it. */\n load(): Promise<void> {\n if (!this.loading) {\n const token = waiter.beginAsync();\n\n this.loading = this.importComponent()\n .then(\n (module) => {\n this.loaded = module.default;\n },\n (error: unknown) => {\n // let a later render try again\n this.loading = undefined;\n throw error;\n }\n )\n .finally(() => waiter.endAsync(token));\n }\n\n return this.loading;\n }\n}\n"],"names":["waiter","buildWaiter","LazyComponent","g","prototype","tracked","i","loading","constructor","importComponent","component","load","loaded","token","beginAsync","then","module","default","error","undefined","finally","endAsync"],"mappings":";;;;AAGA,MAAMA,MAAM,GAAGC,WAAW,CAAC,0CAA0C,CAAC;;AAEtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,CAAI;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAC3BC,OAAO,CAAA,CAAA;AAAA;EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAA,MAAA;EACAC,OAAO;EAEfC,WAAWA,CAASC,eAA8C,EAAE;IAAA,IAAA,CAAhDA,eAA8C,GAA9CA,eAA8C;AAAG,EAAA;EAErE,IAAIC,SAASA,GAAkB;AAC7B,IAAA,KAAK,IAAI,CAACC,IAAI,EAAE;IAEhB,OAAO,IAAI,CAACC,MAAM;AACpB,EAAA;;AAEA;AACAD,EAAAA,IAAIA,GAAkB;AACpB,IAAA,IAAI,CAAC,IAAI,CAACJ,OAAO,EAAE;AACjB,MAAA,MAAMM,KAAK,GAAGb,MAAM,CAACc,UAAU,EAAE;AAEjC,MAAA,IAAI,CAACP,OAAO,GAAG,IAAI,CAACE,eAAe,EAAE,CAClCM,IAAI,CACFC,MAAM,IAAK;AACV,QAAA,IAAI,CAACJ,MAAM,GAAGI,MAAM,CAACC,OAAO;MAC9B,CAAC,EACAC,KAAc,IAAK;AAClB;QACA,IAAI,CAACX,OAAO,GAAGY,SAAS;AACxB,QAAA,MAAMD,KAAK;MACb,CACF,CAAC,CACAE,OAAO,CAAC,MAAMpB,MAAM,CAACqB,QAAQ,CAACR,KAAK,CAAC,CAAC;AAC1C,IAAA;IAEA,OAAO,IAAI,CAACN,OAAO;AACrB,EAAA;AACF;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const INVALID = '[aria-invalid="true"], :invalid:not(form, fieldset)';
|
|
2
|
+
const FOCUSABLE = ['input:not([type="hidden"])', 'textarea', 'select', 'button', '[tabindex]:not([tabindex="-1"])', '[contenteditable]:not([contenteditable="false"])'].join(', ');
|
|
3
|
+
function canFocus(element) {
|
|
4
|
+
return element instanceof HTMLElement && element.matches(FOCUSABLE) && !element.matches(':disabled') &&
|
|
5
|
+
// rendered: not display: none, nor inside it
|
|
6
|
+
element.getClientRects().length > 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Scrolls the first invalid field of `form` into view and focuses its
|
|
11
|
+
* control, as the browser does when its own constraint validation blocks a
|
|
12
|
+
* submit. The first match in document order is a row's label or its
|
|
13
|
+
* control; the whole row is scrolled to, and the first control in it that
|
|
14
|
+
* can take focus is focused. Custom fields that report their validity
|
|
15
|
+
* through a hidden stand-in input thus get their row scrolled to and their
|
|
16
|
+
* visible control focused, never the stand-in (which the browser cannot
|
|
17
|
+
* focus).
|
|
18
|
+
*/
|
|
19
|
+
function revealFirstInvalid(form) {
|
|
20
|
+
if (!form.isConnected) return;
|
|
21
|
+
const invalid = form.querySelector(INVALID);
|
|
22
|
+
if (!invalid) return;
|
|
23
|
+
const row = invalid.closest('.euiFormRow') ?? invalid;
|
|
24
|
+
const control = [row, ...row.querySelectorAll(FOCUSABLE)].find(canFocus);
|
|
25
|
+
row.scrollIntoView({
|
|
26
|
+
block: 'center',
|
|
27
|
+
behavior: 'smooth'
|
|
28
|
+
});
|
|
29
|
+
control?.focus({
|
|
30
|
+
preventScroll: true
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { revealFirstInvalid };
|
|
35
|
+
//# sourceMappingURL=reveal-first-invalid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reveal-first-invalid.js","sources":["../../src/-private/reveal-first-invalid.ts"],"sourcesContent":["const INVALID = '[aria-invalid=\"true\"], :invalid:not(form, fieldset)';\n\nconst FOCUSABLE = [\n 'input:not([type=\"hidden\"])',\n 'textarea',\n 'select',\n 'button',\n '[tabindex]:not([tabindex=\"-1\"])',\n '[contenteditable]:not([contenteditable=\"false\"])'\n].join(', ');\n\nfunction canFocus(element: Element): element is HTMLElement {\n return (\n element instanceof HTMLElement &&\n element.matches(FOCUSABLE) &&\n !element.matches(':disabled') &&\n // rendered: not display: none, nor inside it\n element.getClientRects().length > 0\n );\n}\n\n/**\n * Scrolls the first invalid field of `form` into view and focuses its\n * control, as the browser does when its own constraint validation blocks a\n * submit. The first match in document order is a row's label or its\n * control; the whole row is scrolled to, and the first control in it that\n * can take focus is focused. Custom fields that report their validity\n * through a hidden stand-in input thus get their row scrolled to and their\n * visible control focused, never the stand-in (which the browser cannot\n * focus).\n */\nexport function revealFirstInvalid(form: HTMLElement): void {\n if (!form.isConnected) return;\n\n const invalid = form.querySelector(INVALID);\n if (!invalid) return;\n\n const row = invalid.closest('.euiFormRow') ?? invalid;\n const control = [row, ...row.querySelectorAll(FOCUSABLE)].find(canFocus);\n\n row.scrollIntoView({ block: 'center', behavior: 'smooth' });\n control?.focus({ preventScroll: true });\n}\n"],"names":["INVALID","FOCUSABLE","join","canFocus","element","HTMLElement","matches","getClientRects","length","revealFirstInvalid","form","isConnected","invalid","querySelector","row","closest","control","querySelectorAll","find","scrollIntoView","block","behavior","focus","preventScroll"],"mappings":"AAAA,MAAMA,OAAO,GAAG,qDAAqD;AAErE,MAAMC,SAAS,GAAG,CAChB,4BAA4B,EAC5B,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,iCAAiC,EACjC,kDAAkD,CACnD,CAACC,IAAI,CAAC,IAAI,CAAC;AAEZ,SAASC,QAAQA,CAACC,OAAgB,EAA0B;AAC1D,EAAA,OACEA,OAAO,YAAYC,WAAW,IAC9BD,OAAO,CAACE,OAAO,CAACL,SAAS,CAAC,IAC1B,CAACG,OAAO,CAACE,OAAO,CAAC,WAAW,CAAC;AAC7B;AACAF,EAAAA,OAAO,CAACG,cAAc,EAAE,CAACC,MAAM,GAAG,CAAC;AAEvC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAACC,IAAiB,EAAQ;AAC1D,EAAA,IAAI,CAACA,IAAI,CAACC,WAAW,EAAE;AAEvB,EAAA,MAAMC,OAAO,GAAGF,IAAI,CAACG,aAAa,CAACb,OAAO,CAAC;EAC3C,IAAI,CAACY,OAAO,EAAE;EAEd,MAAME,GAAG,GAAGF,OAAO,CAACG,OAAO,CAAC,aAAa,CAAC,IAAIH,OAAO;AACrD,EAAA,MAAMI,OAAO,GAAG,CAACF,GAAG,EAAE,GAAGA,GAAG,CAACG,gBAAgB,CAAChB,SAAS,CAAC,CAAC,CAACiB,IAAI,CAACf,QAAQ,CAAC;EAExEW,GAAG,CAACK,cAAc,CAAC;AAAEC,IAAAA,KAAK,EAAE,QAAQ;AAAEC,IAAAA,QAAQ,EAAE;AAAS,GAAC,CAAC;EAC3DL,OAAO,EAAEM,KAAK,CAAC;AAAEC,IAAAA,aAAa,EAAE;AAAK,GAAC,CAAC;AACzC;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
|
-
import { tracked } from '@glimmer/tracking';
|
|
3
|
-
import { action } from '@ember/object';
|
|
4
|
-
import {
|
|
2
|
+
import { tracked, cached } from '@glimmer/tracking';
|
|
3
|
+
import { get, action } from '@ember/object';
|
|
4
|
+
import { scheduleOnce } from '@ember/runloop';
|
|
5
5
|
import { buildValidationMessages, notifyValidityChange } from '../../utils/build-validation-messages.js';
|
|
6
6
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
7
7
|
import { setComponentTemplate } from '@ember/component';
|
|
@@ -12,18 +12,62 @@ class ValidatedFormFieldBase extends Component {
|
|
|
12
12
|
//cache for comparing
|
|
13
13
|
lastIsValid;
|
|
14
14
|
lastIsTouched;
|
|
15
|
-
static {
|
|
16
|
-
g(this.prototype, "_validationErrorMessages", [tracked], function () {
|
|
17
|
-
return null;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
#_validationErrorMessages = (i(this, "_validationErrorMessages"), void 0);
|
|
21
15
|
static {
|
|
22
16
|
g(this.prototype, "isTouched", [tracked], function () {
|
|
23
17
|
return false;
|
|
24
18
|
});
|
|
25
19
|
}
|
|
26
20
|
#isTouched = (i(this, "isTouched"), void 0);
|
|
21
|
+
/**
|
|
22
|
+
* The messages of `@validations` and `@customValidations` for the current
|
|
23
|
+
* value. Derived, so a field renders once with its messages on insert and
|
|
24
|
+
* once per value change (they used to be stored after each render, which
|
|
25
|
+
* rendered every field twice).
|
|
26
|
+
*/
|
|
27
|
+
get derivedValidationErrorMessages() {
|
|
28
|
+
return this.derivedValidation.messages;
|
|
29
|
+
}
|
|
30
|
+
// The messages with the value they were derived for (see didUpdateValue).
|
|
31
|
+
static {
|
|
32
|
+
n(this.prototype, "derivedValidationErrorMessages", [cached]);
|
|
33
|
+
}
|
|
34
|
+
get derivedValidation() {
|
|
35
|
+
void this.revision;
|
|
36
|
+
return {
|
|
37
|
+
messages: buildValidationMessages.call(this, this.validationProperty),
|
|
38
|
+
value: get(this, this.validationProperty)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Derives the messages again when a subclass validates a property that is
|
|
42
|
+
// not tracked.
|
|
43
|
+
static {
|
|
44
|
+
n(this.prototype, "derivedValidation", [cached]);
|
|
45
|
+
}
|
|
46
|
+
static {
|
|
47
|
+
g(this.prototype, "revision", [tracked], function () {
|
|
48
|
+
return 0;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
#revision = (i(this, "revision"), void 0);
|
|
52
|
+
static {
|
|
53
|
+
g(this.prototype, "_assignedMessages", [tracked]);
|
|
54
|
+
}
|
|
55
|
+
#_assignedMessages = (i(this, "_assignedMessages"), void 0);
|
|
56
|
+
/**
|
|
57
|
+
* An assignment (subclasses used to store the messages here) shows until
|
|
58
|
+
* the value or the validations change.
|
|
59
|
+
*/
|
|
60
|
+
get _validationErrorMessages() {
|
|
61
|
+
const derived = this.derivedValidationErrorMessages;
|
|
62
|
+
const assigned = this._assignedMessages;
|
|
63
|
+
return assigned && assigned.for === derived ? assigned.messages : derived;
|
|
64
|
+
}
|
|
65
|
+
set _validationErrorMessages(messages) {
|
|
66
|
+
this._assignedMessages = {
|
|
67
|
+
messages,
|
|
68
|
+
for: this.derivedValidationErrorMessages
|
|
69
|
+
};
|
|
70
|
+
}
|
|
27
71
|
formRowElement = null;
|
|
28
72
|
get validations() {
|
|
29
73
|
return this.args.validations || {};
|
|
@@ -81,28 +125,32 @@ class ValidatedFormFieldBase extends Component {
|
|
|
81
125
|
super(owner, args);
|
|
82
126
|
this.args.register?.(this);
|
|
83
127
|
}
|
|
84
|
-
//
|
|
128
|
+
// Run by the field's row on insert: the form finds the field of a row.
|
|
85
129
|
setValidationMessages(ele) {
|
|
86
|
-
this._validationErrorMessages = buildValidationMessages.call(this, this.validationProperty);
|
|
87
130
|
if (ele) {
|
|
88
131
|
this.formRowElement = ele;
|
|
89
132
|
}
|
|
90
133
|
}
|
|
91
|
-
//
|
|
134
|
+
// Run by the field's row when the value or the validations change. The
|
|
135
|
+
// messages update with them; tell the form after this render, in the same
|
|
136
|
+
// run loop.
|
|
92
137
|
static {
|
|
93
138
|
n(this.prototype, "setValidationMessages", [action]);
|
|
94
139
|
}
|
|
95
140
|
didUpdateValue() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}, 1);
|
|
141
|
+
if (get(this, this.validationProperty) !== this.derivedValidation.value) {
|
|
142
|
+
this.revision++;
|
|
143
|
+
}
|
|
144
|
+
scheduleOnce('afterRender', this, this.notifyValidityChangeIfAlive);
|
|
102
145
|
}
|
|
103
146
|
static {
|
|
104
147
|
n(this.prototype, "didUpdateValue", [action]);
|
|
105
148
|
}
|
|
149
|
+
notifyValidityChangeIfAlive() {
|
|
150
|
+
if (!this.isDestroyed && !this.isDestroying) {
|
|
151
|
+
this.notifyValidityChange();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
106
154
|
notifyValidityChange() {
|
|
107
155
|
notifyValidityChange(this, this.args.onValidityChange);
|
|
108
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-base.js","sources":["../../../src/components/validated-form/field-base.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { later } from '@ember/runloop';\nimport type Owner from '@ember/owner';\n\nimport {\n buildValidationMessages,\n notifyValidityChange\n} from '../../utils/build-validation-messages.js';\n\nimport type { ComponentLike } from '@glint/template';\n\n/**\n * Args every ValidatedForm field takes (on top of EuiFormRow's and its\n * control's). The form's yielded fields pass `register`, `unregister`,\n * `onValidityChange` and `formId` for you.\n */\nexport interface FieldBaseSignature<T = ComponentLike> {\n Args: {\n /** Id of the control; the row's label points to it. Defaults to a random id. */\n id?: string;\n /** The field's value. Update it in `@onChange`. */\n value: any;\n /** The row's label. */\n label?: string;\n /** Errors from outside (e.g. the server), shown with the validation errors. */\n error?: string[];\n /** Options, for fields with options (select, radios, checkboxes, combo box). */\n options?: any[];\n /**\n * ember-validators validations by name, e.g.\n * `(hash presence=(hash presence=true) length=(hash min=3))` or\n * `format=(hash type=\"email\")`. Errors show once the field is touched\n * (blurred, or the form submitted).\n */\n validations?: any;\n /**\n * Each validation returns `true` when valid; otherwise `false` (generic\n * \"is invalid\" message), a message string, or an ember-validators result\n * (`{ type, context }`).\n */\n customValidations?: {\n validation(\n value: any,\n options?: Record<string, unknown>\n ): boolean | string | { type?: string; context?: Record<string, unknown> };\n params?: Record<string, unknown>;\n }[];\n /** Classes for the EuiFormRow. */\n rowClasses?: string;\n /** @deprecated Has no effect. */\n rowExtra?: Record<string, unknown>;\n /** Called with the new value; update `@value` here. */\n onChange: (value: any) => void;\n /** @private Set by ValidatedForm. */\n onValidityChange: (isValid: boolean) => void;\n /** @private Set by ValidatedForm. */\n register: (field: T) => void;\n /** @private Set by ValidatedForm. */\n unregister: (field: T) => void;\n };\n}\n\nexport default class ValidatedFormFieldBase<\n T extends FieldBaseSignature = FieldBaseSignature\n> extends Component<T> {\n validationProperty = 'args.value';\n\n //cache for comparing\n lastIsValid?: boolean;\n lastIsTouched?: boolean;\n\n @tracked _validationErrorMessages: null | string[] = null;\n\n @tracked isTouched = false;\n\n formRowElement: HTMLElement | null = null;\n\n get validations() {\n return this.args.validations || {};\n }\n\n get hasErrorMessages(): boolean {\n return !!this._validationErrorMessages?.length || this.error?.length > 0;\n }\n\n get isValid() {\n return !this.isInvalid;\n }\n\n get isInvalid() {\n return this.hasErrorMessages;\n }\n\n get isInvalidAndTouched() {\n return !!(this.isInvalid && this.isTouched);\n }\n\n get formHasBeenValidated() {\n return this.isTouched;\n }\n\n set formHasBeenValidated(value) {\n this.isTouched = value;\n }\n\n get customValidations(): NonNullable<\n FieldBaseSignature['Args']['customValidations']\n > {\n return this.args.customValidations || [];\n }\n\n get rowClasses(): string {\n return this.args.rowClasses || '';\n }\n\n get rowExtra() {\n return this.args.rowExtra || {};\n }\n\n get label(): string {\n return this.args.label || '';\n }\n\n get error(): string[] {\n return this.args.error || [];\n }\n\n get options(): any[] {\n return this.args.options || [];\n }\n\n get validationErrorMessages() {\n const error = [];\n\n if (this.error.length > 0) {\n error.push(...this.error);\n }\n\n if (\n this._validationErrorMessages &&\n this._validationErrorMessages.length > 0\n ) {\n error.push(...this._validationErrorMessages);\n }\n\n if (error.length === 0) {\n return null;\n }\n\n return error;\n }\n\n constructor(owner: Owner, args: T['Args']) {\n super(owner, args);\n this.args.register?.(this as unknown as ComponentLike);\n }\n\n //Should be executed by the child on start\n @action\n setValidationMessages(ele?: HTMLElement) {\n this._validationErrorMessages = buildValidationMessages.call(\n this,\n this.validationProperty\n );\n\n if (ele) {\n this.formRowElement = ele;\n }\n }\n\n //Should be executed by the child on value update\n @action\n didUpdateValue() {\n later(() => {\n if (!this.isDestroyed && !this.isDestroying) {\n this.setValidationMessages();\n this.notifyValidityChange();\n }\n }, 1);\n }\n\n @action\n notifyValidityChange() {\n notifyValidityChange(this, this.args.onValidityChange);\n }\n\n @action\n setIsTouched(val: boolean) {\n this.isTouched = val;\n this.notifyValidityChange();\n }\n\n /**\n * This is just a default handleChange, you should override this method\n * if you need to or use whatever mechanism to bubble the changed\n * value outside and then notifyValidityChanges\n *\n * @override\n * @param {*} e\n */\n @action\n handleChange(e: Event) {\n const value = (e.target as HTMLInputElement).value;\n\n this.args.onChange(value);\n this.notifyValidityChange();\n }\n\n willDestroy(): void {\n super.willDestroy();\n \n this.args.unregister?.(this as unknown as ComponentLike);\n this.formRowElement = null;\n }\n\n <template>\n {{!@glint-expect-error}}\n {{yield this}}\n </template>\n}\n"],"names":["ValidatedFormFieldBase","Component","validationProperty","lastIsValid","lastIsTouched","g","prototype","tracked","i","formRowElement","validations","args","hasErrorMessages","_validationErrorMessages","length","error","isValid","isInvalid","isInvalidAndTouched","isTouched","formHasBeenValidated","value","customValidations","rowClasses","rowExtra","label","options","validationErrorMessages","push","constructor","owner","register","setValidationMessages","ele","buildValidationMessages","call","n","action","didUpdateValue","later","isDestroyed","isDestroying","notifyValidityChange","onValidityChange","setIsTouched","val","handleChange","e","target","onChange","willDestroy","unregister","setComponentTemplate","precompileTemplate","strictMode"],"mappings":";;;;;;;;;AAgEe,MAAMA,sBAAA,SAEXC,SAAA,CAAU;AAClBC,EAAAA,kBAAA,GAAqB,YAAA;AAErB;EACAC,WAAA;EACAC,aAAA;AAAwB,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,0BAAA,EAAA,CAEvBC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAoD,IAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,yBAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,0BAAA,CAAA,EAAA,MAAA;AAAA,EAAA;IAAAH,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CAEpDC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAoB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,UAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAA,MAAA;AAErBC,EAAAA,cAAA,GAAqC,IAAA;EAErC,IAAIC,WAAAA,GAAc;AAChB,IAAA,OAAO,IAAI,CAACC,IAAI,CAACD,WAAW,IAAI,EAAC;AACnC,EAAA;EAEA,IAAIE,gBAAAA,GAA4B;AAC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esContent":["import Component from '@glimmer/component';\nimport { cached, tracked } from '@glimmer/tracking';\nimport { action, get } from '@ember/object';\nimport { scheduleOnce } from '@ember/runloop';\nimport type Owner from '@ember/owner';\n\nimport {\n buildValidationMessages,\n notifyValidityChange\n} from '../../utils/build-validation-messages.js';\n\nimport type { ComponentLike } from '@glint/template';\n\n/**\n * Args every ValidatedForm field takes (on top of EuiFormRow's and its\n * control's). The form's yielded fields pass `register`, `unregister`,\n * `onValidityChange` and `formId` for you.\n */\nexport interface FieldBaseSignature<T = ComponentLike> {\n Args: {\n /** Id of the control; the row's label points to it. Defaults to a random id. */\n id?: string;\n /** The field's value. Update it in `@onChange`. */\n value: any;\n /** The row's label. */\n label?: string;\n /** Errors from outside (e.g. the server), shown with the validation errors. */\n error?: string[];\n /** Options, for fields with options (select, radios, checkboxes, combo box). */\n options?: any[];\n /**\n * ember-validators validations by name, e.g.\n * `(hash presence=(hash presence=true) length=(hash min=3))` or\n * `format=(hash type=\"email\")`. Errors show once the field is touched\n * (blurred, or the form submitted).\n */\n validations?: any;\n /**\n * Each validation returns `true` when valid; otherwise `false` (generic\n * \"is invalid\" message), a message string, or an ember-validators result\n * (`{ type, context }`).\n */\n customValidations?: {\n validation(\n value: any,\n options?: Record<string, unknown>\n ): boolean | string | { type?: string; context?: Record<string, unknown> };\n params?: Record<string, unknown>;\n }[];\n /** Classes for the EuiFormRow. */\n rowClasses?: string;\n /** @deprecated Has no effect. */\n rowExtra?: Record<string, unknown>;\n /** Called with the new value; update `@value` here. */\n onChange: (value: any) => void;\n /** @private Set by ValidatedForm. */\n onValidityChange: (isValid: boolean) => void;\n /** @private Set by ValidatedForm. */\n register: (field: T) => void;\n /** @private Set by ValidatedForm. */\n unregister: (field: T) => void;\n };\n}\n\nexport default class ValidatedFormFieldBase<\n T extends FieldBaseSignature = FieldBaseSignature\n> extends Component<T> {\n validationProperty = 'args.value';\n\n //cache for comparing\n lastIsValid?: boolean;\n lastIsTouched?: boolean;\n\n @tracked isTouched = false;\n\n /**\n * The messages of `@validations` and `@customValidations` for the current\n * value. Derived, so a field renders once with its messages on insert and\n * once per value change (they used to be stored after each render, which\n * rendered every field twice).\n */\n @cached\n get derivedValidationErrorMessages(): string[] {\n return this.derivedValidation.messages;\n }\n\n // The messages with the value they were derived for (see didUpdateValue).\n @cached\n private get derivedValidation(): { messages: string[]; value: unknown } {\n void this.revision;\n\n return {\n messages: buildValidationMessages.call(this, this.validationProperty),\n value: get(this, this.validationProperty as keyof this)\n };\n }\n\n // Derives the messages again when a subclass validates a property that is\n // not tracked.\n @tracked private revision = 0;\n\n /**\n * An assignment (subclasses used to store the messages here) shows until\n * the value or the validations change.\n */\n @tracked private _assignedMessages?: {\n messages: null | string[];\n for: string[];\n };\n\n get _validationErrorMessages(): null | string[] {\n const derived = this.derivedValidationErrorMessages;\n const assigned = this._assignedMessages;\n\n return assigned && assigned.for === derived ? assigned.messages : derived;\n }\n\n set _validationErrorMessages(messages: null | string[]) {\n this._assignedMessages = {\n messages,\n for: this.derivedValidationErrorMessages\n };\n }\n\n formRowElement: HTMLElement | null = null;\n\n get validations() {\n return this.args.validations || {};\n }\n\n get hasErrorMessages(): boolean {\n return !!this._validationErrorMessages?.length || this.error?.length > 0;\n }\n\n get isValid() {\n return !this.isInvalid;\n }\n\n get isInvalid() {\n return this.hasErrorMessages;\n }\n\n get isInvalidAndTouched() {\n return !!(this.isInvalid && this.isTouched);\n }\n\n get formHasBeenValidated() {\n return this.isTouched;\n }\n\n set formHasBeenValidated(value) {\n this.isTouched = value;\n }\n\n get customValidations(): NonNullable<\n FieldBaseSignature['Args']['customValidations']\n > {\n return this.args.customValidations || [];\n }\n\n get rowClasses(): string {\n return this.args.rowClasses || '';\n }\n\n get rowExtra() {\n return this.args.rowExtra || {};\n }\n\n get label(): string {\n return this.args.label || '';\n }\n\n get error(): string[] {\n return this.args.error || [];\n }\n\n get options(): any[] {\n return this.args.options || [];\n }\n\n get validationErrorMessages() {\n const error = [];\n\n if (this.error.length > 0) {\n error.push(...this.error);\n }\n\n if (\n this._validationErrorMessages &&\n this._validationErrorMessages.length > 0\n ) {\n error.push(...this._validationErrorMessages);\n }\n\n if (error.length === 0) {\n return null;\n }\n\n return error;\n }\n\n constructor(owner: Owner, args: T['Args']) {\n super(owner, args);\n this.args.register?.(this as unknown as ComponentLike);\n }\n\n // Run by the field's row on insert: the form finds the field of a row.\n @action\n setValidationMessages(ele?: HTMLElement) {\n if (ele) {\n this.formRowElement = ele;\n }\n }\n\n // Run by the field's row when the value or the validations change. The\n // messages update with them; tell the form after this render, in the same\n // run loop.\n @action\n didUpdateValue() {\n if (\n get(this, this.validationProperty as keyof this) !==\n this.derivedValidation.value\n ) {\n this.revision++;\n }\n\n scheduleOnce('afterRender', this, this.notifyValidityChangeIfAlive);\n }\n\n private notifyValidityChangeIfAlive() {\n if (!this.isDestroyed && !this.isDestroying) {\n this.notifyValidityChange();\n }\n }\n\n @action\n notifyValidityChange() {\n notifyValidityChange(this, this.args.onValidityChange);\n }\n\n @action\n setIsTouched(val: boolean) {\n this.isTouched = val;\n this.notifyValidityChange();\n }\n\n /**\n * This is just a default handleChange, you should override this method\n * if you need to or use whatever mechanism to bubble the changed\n * value outside and then notifyValidityChanges\n *\n * @override\n * @param {*} e\n */\n @action\n handleChange(e: Event) {\n const value = (e.target as HTMLInputElement).value;\n\n this.args.onChange(value);\n this.notifyValidityChange();\n }\n\n willDestroy(): void {\n super.willDestroy();\n \n this.args.unregister?.(this as unknown as ComponentLike);\n this.formRowElement = null;\n }\n\n <template>\n {{!@glint-expect-error}}\n {{yield this}}\n </template>\n}\n"],"names":["ValidatedFormFieldBase","Component","validationProperty","lastIsValid","lastIsTouched","g","prototype","tracked","i","derivedValidationErrorMessages","derivedValidation","messages","n","cached","revision","buildValidationMessages","call","value","get","_validationErrorMessages","derived","assigned","_assignedMessages","for","formRowElement","validations","args","hasErrorMessages","length","error","isValid","isInvalid","isInvalidAndTouched","isTouched","formHasBeenValidated","customValidations","rowClasses","rowExtra","label","options","validationErrorMessages","push","constructor","owner","register","setValidationMessages","ele","action","didUpdateValue","scheduleOnce","notifyValidityChangeIfAlive","isDestroyed","isDestroying","notifyValidityChange","onValidityChange","setIsTouched","val","handleChange","e","target","onChange","willDestroy","unregister","setComponentTemplate","precompileTemplate","strictMode"],"mappings":";;;;;;;;;AAgEe,MAAMA,sBAAA,SAEXC,SAAA,CAAU;AAClBC,EAAAA,kBAAA,GAAqB,YAAA;AAErB;EACAC,WAAA;EACAC,aAAA;AAAwB,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CAEvBC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAoB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,UAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAA,MAAA;AAErB;;;;;AAKC;EACD,IACIC,8BAAAA,GAA2C;AAC7C,IAAA,OAAO,IAAI,CAACC,iBAAiB,CAACC,QAAQ;AACxC,EAAA;AAEA;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAN,SAAA,EAAA,gCAAA,EAAA,CALCO,MAAA,CAAA,CAAA;AAAA;EAMD,IACYH,iBAAAA,GAA4D;IACtE,KAAK,IAAI,CAACI,QAAQ;IAElB,OAAO;MACLH,QAAA,EAAUI,wBAAwBC,IAAI,CAAC,IAAI,EAAE,IAAI,CAACd,kBAAkB,CAAA;AACpEe,MAAAA,KAAA,EAAOC,IAAI,IAAI,EAAE,IAAI,CAAChB,kBAAgC;KACxD;AACF,EAAA;AAEA;AACA;AAAA,EAAA;IAAAU,CAAA,CAAA,IAAA,CAAAN,SAAA,EAAA,mBAAA,EAAA,CAXCO,MAAA,CAAA,CAAA;AAAA;AAAA,EAAA;IAAAR,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,UAAA,EAAA,CAYAC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA2B,CAAA;AAAA,IAAA,CAAA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IACzB,IAAI,CAACvB,SAAS,GAAGuB,GAAA;IACjB,IAAI,CAACH,oBAAoB,EAAA;AAC3B,EAAA;AAEA;;;;;;;AAOC;AAPD,EAAA;IAAAzC,CAAA,CAAA,IAAA,CAAAN,SAAA,EAAA,cAAA,EAAA,CANCyC,MAAA,CAAA,CAAA;AAAA;EAeDU,YAAAA,CAAaC,CAAQ,EAAE;AACrB,IAAA,MAAMzC,QAASyC,CAAA,CAAEC,MAAM,CAAsB1C,KAAK;AAElD,IAAA,IAAI,CAACS,IAAI,CAACkC,QAAQ,CAAC3C,KAAA,CAAA;IACnB,IAAI,CAACoC,oBAAoB,EAAA;AAC3B,EAAA;AAAA,EAAA;IAAAzC,CAAA,CAAA,IAAA,CAAAN,SAAA,EAAA,cAAA,EAAA,CANCyC,MAAA,CAAA,CAAA;AAAA;AAQDc,EAAAA,WAAAA,GAAoB;IAClB,KAAK,CAACA,WAAA,EAAA;AAEN,IAAA,IAAI,CAACnC,IAAI,CAACoC,UAAU,GAAG,IAAmB,CAAA;IAC1C,IAAI,CAACtC,cAAc,GAAG,IAAA;AACxB,EAAA;AAEA,EAAA;IAAAuC,oBAAA,CAAAC,kBAAA,CAAA,8CAAA,EAGA;MAAAC,UAAA,EAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -2,18 +2,20 @@ import { fn } from '@ember/helper';
|
|
|
2
2
|
import { action } from '@ember/object';
|
|
3
3
|
import didInsert from '@ember/render-modifiers/modifiers/did-insert';
|
|
4
4
|
import didUpdate from '@ember/render-modifiers/modifiers/did-update';
|
|
5
|
-
import EuiComboBox from '@ember-eui/core/components/eui-combo-box';
|
|
6
5
|
import EuiFormRow from '@ember-eui/core/components/eui-form-row';
|
|
7
6
|
import { argOrDefault } from '@ember-eui/core/helpers';
|
|
8
7
|
import optional from '@nullvoxpopuli/ember-composable-helpers/helpers/optional';
|
|
9
8
|
import queue from '@nullvoxpopuli/ember-composable-helpers/helpers/queue';
|
|
10
9
|
import { or, not } from 'ember-truth-helpers';
|
|
10
|
+
import { LazyComponent } from '../../-private/lazy-component.js';
|
|
11
11
|
import randomId from '../../-private/random-id.js';
|
|
12
12
|
import ValidatedFormFieldBase from './field-base.js';
|
|
13
13
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
14
14
|
import { setComponentTemplate } from '@ember/component';
|
|
15
15
|
import { n } from 'decorator-transforms/runtime-esm';
|
|
16
16
|
|
|
17
|
+
// imported on first render (see LazyComponent)
|
|
18
|
+
const euiComboBox = new LazyComponent(() => import('@ember-eui/core/components/eui-combo-box'));
|
|
17
19
|
class ValidatedFormFieldComboBox extends ValidatedFormFieldBase {
|
|
18
20
|
validationProperty = 'args.selectedOptions';
|
|
19
21
|
//@ts-expect-error
|
|
@@ -24,8 +26,11 @@ class ValidatedFormFieldComboBox extends ValidatedFormFieldBase {
|
|
|
24
26
|
static {
|
|
25
27
|
n(this.prototype, "handleChange", [action]);
|
|
26
28
|
}
|
|
29
|
+
get EuiComboBox() {
|
|
30
|
+
return euiComboBox.component;
|
|
31
|
+
}
|
|
27
32
|
static {
|
|
28
|
-
setComponentTemplate(precompileTemplate("{{#let (argOrDefault @id (randomId)) as |theId|}}\n
|
|
33
|
+
setComponentTemplate(precompileTemplate("{{#let this.EuiComboBox as |EuiComboBox|}}\n {{#if EuiComboBox}}\n {{#let (argOrDefault @id (randomId)) as |theId|}}\n <EuiFormRow class={{this.rowClasses}} @labelType={{@labelType}} @display={{@display}} @hasEmptyLabelSpace={{@hasEmptyLabelSpace}} @fullWidth={{@fullWidth}} @hasChildLabel={{@hasChildLabel}} @label={{this.label}} @labelAppend={{@labelAppend}} @id={{theId}} @isInvalid={{this.isInvalidAndTouched}} @error={{this.validationErrorMessages}} @helpText={{@helpText}} @errorClasses={{@errorClasses}} @isFakeLabelBlock={{not (has-block \"label\")}} @isFakeHelpTextBlock={{not (has-block \"helpText\")}} {{didInsert this.setValidationMessages}} {{didUpdate this.didUpdateValue @validations}} {{didUpdate this.didUpdateValue @selectedOptions}}>\n <:label>\n {{yield to=\"label\"}}\n </:label>\n <:field>\n {{#let (component EuiComboBox onChange=this.handleChange options=this.options singleSelection=@singleSelection selectedOptions=@selectedOptions searchEnabled=(argOrDefault @searchEnabled true) searchField=@searchField search=@search searchMessage=@searchMessage searchMessageComponent=@searchMessageComponent searchPlaceholder=@searchPlaceholder placeholder=@placeholder placeholderComponent=@placeholderComponent loadingMessage=@loadingMessage noMatchesMessage=@noMatchesMessage noMatchesMessageComponent=@noMatchesMessageComponent beforeOptionsComponent=@beforeOptionsComponent afterOptionsComponent=@afterOptionsComponent selectedItemComponent=@selectedItemComponent dropdownClass=@dropdownClass optionsClass=@optionsClass onCreateOption=@onCreateOption alwaysShowCreateOption=@alwaysShowCreateOption customOptionText=@customOptionText delimiter=@delimiter isCaseSensitive=@isCaseSensitive sortMatchesBy=@sortMatchesBy matcher=@matcher optionMatcher=@optionMatcher typeAheadOptionMatcher=@typeAheadOptionMatcher async=@async onSearchChange=@onSearchChange noSuggestions=@noSuggestions truncationProps=@truncationProps rowHeight=@rowHeight onFocusBadge=@onFocusBadge prepend=@prepend append=@append triggerIcon=@triggerIcon isInvalid=this.isInvalidAndTouched isClearable=@isClearable isLoading=@isLoading isDisabled=@isDisabled readOnly=@readOnly fullWidth=@fullWidth compressed=@compressed closeOnSelect=@closeOnSelect autoFocus=(or @autoFocus @autofocus) initiallyOpen=@initiallyOpen defaultHighlighted=@defaultHighlighted matchTriggerWidth=@matchTriggerWidth renderInPlace=@renderInPlace horizontalPosition=@horizontalPosition verticalPosition=@verticalPosition destination=@destination preventScroll=@preventScroll calculatePosition=@calculatePosition eventType=@eventType tabindex=@tabindex ariaLabel=@ariaLabel ariaLabelledBy=@ariaLabelledBy required=@required triggerRole=@triggerRole title=@title triggerId=@triggerId removeTag=@removeTag onInput=@onInput onKeydown=@onKeydown registerApi=@registerApi onBlur=(queue (fn this.setIsTouched true) (optional @onBlur)) onFocus=@onFocus onClose=@onClose onOpen=@onOpen extra=@extra) as |ComboBox|}}\n {{#if (has-block)}}\n <ComboBox class={{@fieldClasses}} ...attributes as |opt index search|>\n {{yield opt index search}}\n </ComboBox>\n {{else}}\n {{!-- without a block, EuiComboBox renders the option labels --}}\n <ComboBox class={{@fieldClasses}} ...attributes />\n {{/if}}\n {{/let}}\n </:field>\n <:helpText as |helpText|>\n {{yield helpText to=\"helpText\"}}\n </:helpText>\n </EuiFormRow>\n {{/let}}\n {{/if}}\n{{/let}}", {
|
|
29
34
|
strictMode: true,
|
|
30
35
|
scope: () => ({
|
|
31
36
|
argOrDefault,
|
|
@@ -34,7 +39,6 @@ class ValidatedFormFieldComboBox extends ValidatedFormFieldBase {
|
|
|
34
39
|
not,
|
|
35
40
|
didInsert,
|
|
36
41
|
didUpdate,
|
|
37
|
-
EuiComboBox,
|
|
38
42
|
or,
|
|
39
43
|
queue,
|
|
40
44
|
fn,
|