@hokulea/ember 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -17
- package/addon-main.cjs +5 -0
- package/declarations/-private/form/components/{description.d.ts → description.gts.d.ts} +1 -1
- package/declarations/-private/form/components/description.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/{errors.d.ts → errors.gts.d.ts} +2 -2
- package/declarations/-private/form/components/errors.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/{field.d.ts → field.gts.d.ts} +22 -16
- package/declarations/-private/form/components/field.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{checkbox.d.ts → checkbox.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/checkbox.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{currency.d.ts → currency.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/currency.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{date.d.ts → date.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/date.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{email.d.ts → email.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/email.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{list.d.ts → list.gts.d.ts} +3 -3
- package/declarations/-private/form/components/fields/list.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{multiple-choice.d.ts → multiple-choice.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/multiple-choice.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{number.d.ts → number.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/number.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{password.d.ts → password.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/password.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{phone.d.ts → phone.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/phone.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{range.d.ts → range.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/range.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{select.d.ts → select.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/select.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{singular-choice.d.ts → singular-choice.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/singular-choice.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{text-area.d.ts → text-area.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/text-area.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/fields/{text.d.ts → text.gts.d.ts} +2 -2
- package/declarations/-private/form/components/fields/text.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/{label.d.ts → label.gts.d.ts} +1 -1
- package/declarations/-private/form/components/label.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/{reset.d.ts → reset.gts.d.ts} +1 -1
- package/declarations/-private/form/components/reset.gts.d.ts.map +1 -0
- package/declarations/-private/form/components/{submit.d.ts → submit.gts.d.ts} +1 -1
- package/declarations/-private/form/components/submit.gts.d.ts.map +1 -0
- package/declarations/-private/form/modifiers/capture-events.d.ts.map +1 -1
- package/declarations/-private/form/modifiers/manage-validation.d.ts +8 -5
- package/declarations/-private/form/modifiers/manage-validation.d.ts.map +1 -1
- package/declarations/-private/helpers.d.ts.map +1 -1
- package/declarations/-private/stories.d.ts +2 -0
- package/declarations/-private/stories.d.ts.map +1 -0
- package/declarations/components/-stories.d.ts +3 -0
- package/declarations/components/-stories.d.ts.map +1 -0
- package/declarations/components/{app-header.d.ts → app-header.gts.d.ts} +1 -2
- package/declarations/components/app-header.gts.d.ts.map +1 -0
- package/declarations/components/{box.d.ts → box.gts.d.ts} +1 -1
- package/declarations/components/box.gts.d.ts.map +1 -0
- package/declarations/components/{button.d.ts → button.gts.d.ts} +1 -1
- package/declarations/components/button.gts.d.ts.map +1 -0
- package/declarations/components/{card.d.ts → card.gts.d.ts} +1 -1
- package/declarations/components/card.gts.d.ts.map +1 -0
- package/declarations/components/{checkbox.d.ts → checkbox.gts.d.ts} +2 -2
- package/declarations/components/checkbox.gts.d.ts.map +1 -0
- package/declarations/components/{currency-input.d.ts → currency-input.gts.d.ts} +2 -2
- package/declarations/components/currency-input.gts.d.ts.map +1 -0
- package/declarations/components/{date-input.d.ts → date-input.gts.d.ts} +2 -2
- package/declarations/components/date-input.gts.d.ts.map +1 -0
- package/declarations/components/{email-input.d.ts → email-input.gts.d.ts} +2 -2
- package/declarations/components/email-input.gts.d.ts.map +1 -0
- package/declarations/components/{form.d.ts → form.gts.d.ts} +27 -31
- package/declarations/components/form.gts.d.ts.map +1 -0
- package/declarations/components/{icon-button.d.ts → icon-button.gts.d.ts} +4 -5
- package/declarations/components/icon-button.gts.d.ts.map +1 -0
- package/declarations/components/icon.gts.d.ts +14 -0
- package/declarations/components/icon.gts.d.ts.map +1 -0
- package/declarations/components/{input-builder.d.ts → input-builder.gts.d.ts} +1 -1
- package/declarations/components/input-builder.gts.d.ts.map +1 -0
- package/declarations/components/{list.d.ts → list.gts.d.ts} +1 -1
- package/declarations/components/list.gts.d.ts.map +1 -0
- package/declarations/components/{menu.d.ts → menu.gts.d.ts} +3 -4
- package/declarations/components/menu.gts.d.ts.map +1 -0
- package/declarations/components/{number-input.d.ts → number-input.gts.d.ts} +2 -2
- package/declarations/components/number-input.gts.d.ts.map +1 -0
- package/declarations/components/{page.d.ts → page.gts.d.ts} +6 -2
- package/declarations/components/page.gts.d.ts.map +1 -0
- package/declarations/components/{password-input.d.ts → password-input.gts.d.ts} +2 -2
- package/declarations/components/password-input.gts.d.ts.map +1 -0
- package/declarations/components/{phone-input.d.ts → phone-input.gts.d.ts} +2 -2
- package/declarations/components/phone-input.gts.d.ts.map +1 -0
- package/declarations/components/{popover.d.ts → popover.gts.d.ts} +1 -1
- package/declarations/components/popover.gts.d.ts.map +1 -0
- package/declarations/components/{radio.d.ts → radio.gts.d.ts} +2 -2
- package/declarations/components/radio.gts.d.ts.map +1 -0
- package/declarations/components/{range-input.d.ts → range-input.gts.d.ts} +2 -2
- package/declarations/components/range-input.gts.d.ts.map +1 -0
- package/declarations/components/{section.d.ts → section.gts.d.ts} +1 -1
- package/declarations/components/section.gts.d.ts.map +1 -0
- package/declarations/components/{select.d.ts → select.gts.d.ts} +1 -1
- package/declarations/components/select.gts.d.ts.map +1 -0
- package/declarations/components/{tabs.d.ts → tabs.gts.d.ts} +6 -5
- package/declarations/components/tabs.gts.d.ts.map +1 -0
- package/declarations/components/{text-area.d.ts → text-area.gts.d.ts} +2 -2
- package/declarations/components/text-area.gts.d.ts.map +1 -0
- package/declarations/components/{text-input.d.ts → text-input.gts.d.ts} +2 -2
- package/declarations/components/text-input.gts.d.ts.map +1 -0
- package/declarations/index.d.ts +14 -11
- package/declarations/index.d.ts.map +1 -1
- package/declarations/services/-hokulea.d.ts +5 -0
- package/declarations/services/-hokulea.d.ts.map +1 -0
- package/declarations/template-registry.d.ts +1 -1
- package/declarations/template-registry.d.ts.map +1 -1
- package/declarations/test-support/index.d.ts +18 -18
- package/declarations/test-support/index.d.ts.map +1 -1
- package/declarations/test-support/page-objects/-private/choices.d.ts +1 -2
- package/declarations/test-support/page-objects/-private/choices.d.ts.map +1 -1
- package/declarations/test-support/page-objects/-private/field.d.ts +11 -33
- package/declarations/test-support/page-objects/-private/field.d.ts.map +1 -1
- package/declarations/test-support/page-objects/app-header.d.ts +3 -3
- package/declarations/test-support/page-objects/app-header.d.ts.map +1 -1
- package/declarations/test-support/page-objects/choice.d.ts +1 -1
- package/declarations/test-support/page-objects/choice.d.ts.map +1 -1
- package/declarations/test-support/page-objects/form.d.ts +4 -2
- package/declarations/test-support/page-objects/form.d.ts.map +1 -1
- package/declarations/test-support/page-objects/icon-button.d.ts +1 -1
- package/declarations/test-support/page-objects/icon-button.d.ts.map +1 -1
- package/declarations/test-support/page-objects/icon.d.ts +1 -2
- package/declarations/test-support/page-objects/icon.d.ts.map +1 -1
- package/declarations/test-support/page-objects/input-builder.d.ts +2 -2
- package/declarations/test-support/page-objects/input-builder.d.ts.map +1 -1
- package/declarations/test-support/page-objects/menu.d.ts +1 -1
- package/declarations/test-support/page-objects/menu.d.ts.map +1 -1
- package/declarations/test-support/page-objects/tabs.d.ts.map +1 -1
- package/declarations/test-support/page-objects/text-area.d.ts +1 -1
- package/declarations/test-support/page-objects/text-area.d.ts.map +1 -1
- package/dist/{-button-CJL1yb2d.js → -button-KUaJCQaB.js} +2 -2
- package/dist/-button-KUaJCQaB.js.map +1 -0
- package/dist/-input-DGR-n9U_.js.map +1 -1
- package/dist/_app_/services/-hokulea.js +1 -0
- package/dist/components/app-header.js +35 -40
- package/dist/components/app-header.js.map +1 -1
- package/dist/components/box.js +3 -3
- package/dist/components/box.js.map +1 -1
- package/dist/components/button.js +4 -4
- package/dist/components/button.js.map +1 -1
- package/dist/components/card.js +3 -3
- package/dist/components/card.js.map +1 -1
- package/dist/components/checkbox.js +3 -3
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/currency-input.js +3 -3
- package/dist/components/currency-input.js.map +1 -1
- package/dist/components/date-input.js +3 -3
- package/dist/components/date-input.js.map +1 -1
- package/dist/components/email-input.js +3 -3
- package/dist/components/email-input.js.map +1 -1
- package/dist/components/form.js +287 -295
- package/dist/components/form.js.map +1 -1
- package/dist/components/icon-button.js +8 -6
- package/dist/components/icon-button.js.map +1 -1
- package/dist/components/icon.js +9 -34
- package/dist/components/icon.js.map +1 -1
- package/dist/components/input-builder.js +2 -2
- package/dist/components/input-builder.js.map +1 -1
- package/dist/components/list.js +17 -17
- package/dist/components/list.js.map +1 -1
- package/dist/components/menu.js +18 -23
- package/dist/components/menu.js.map +1 -1
- package/dist/components/number-input.js +3 -3
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/page.js +33 -35
- package/dist/components/page.js.map +1 -1
- package/dist/components/password-input.js +3 -3
- package/dist/components/password-input.js.map +1 -1
- package/dist/components/phone-input.js +3 -3
- package/dist/components/phone-input.js.map +1 -1
- package/dist/components/popover.js +2 -2
- package/dist/components/popover.js.map +1 -1
- package/dist/components/radio.js +3 -3
- package/dist/components/radio.js.map +1 -1
- package/dist/components/range-input.js +15 -15
- package/dist/components/range-input.js.map +1 -1
- package/dist/components/section.js +10 -10
- package/dist/components/section.js.map +1 -1
- package/dist/components/select.js +10 -10
- package/dist/components/select.js.map +1 -1
- package/dist/components/tabs.js +28 -27
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/text-area.js +3 -3
- package/dist/components/text-area.js.map +1 -1
- package/dist/components/text-input.js +3 -3
- package/dist/components/text-input.js.map +1 -1
- package/dist/disabled-B_FQ0Z51.js.map +1 -1
- package/dist/helpers/popover.js +3 -3
- package/dist/helpers/popover.js.map +1 -1
- package/dist/{helpers-DApiJrHl.js → helpers-DS9du02l.js} +4 -2
- package/dist/helpers-DS9du02l.js.map +1 -0
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/services/-hokulea.js +15 -0
- package/dist/services/-hokulea.js.map +1 -0
- package/dist/test-support/index.js +12 -14
- package/dist/test-support/index.js.map +1 -1
- package/package.json +93 -84
- package/addon-main.js +0 -49
- package/declarations/-private/form/components/description.d.ts.map +0 -1
- package/declarations/-private/form/components/errors.d.ts.map +0 -1
- package/declarations/-private/form/components/field.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/checkbox.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/currency.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/date.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/email.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/list.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/multiple-choice.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/number.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/password.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/phone.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/range.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/select.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/singular-choice.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/text-area.d.ts.map +0 -1
- package/declarations/-private/form/components/fields/text.d.ts.map +0 -1
- package/declarations/-private/form/components/label.d.ts.map +0 -1
- package/declarations/-private/form/components/reset.d.ts.map +0 -1
- package/declarations/-private/form/components/submit.d.ts.map +0 -1
- package/declarations/components/app-header.d.ts.map +0 -1
- package/declarations/components/box.d.ts.map +0 -1
- package/declarations/components/button.d.ts.map +0 -1
- package/declarations/components/card.d.ts.map +0 -1
- package/declarations/components/checkbox.d.ts.map +0 -1
- package/declarations/components/currency-input.d.ts.map +0 -1
- package/declarations/components/date-input.d.ts.map +0 -1
- package/declarations/components/email-input.d.ts.map +0 -1
- package/declarations/components/form.d.ts.map +0 -1
- package/declarations/components/icon-button.d.ts.map +0 -1
- package/declarations/components/icon.d.ts +0 -13698
- package/declarations/components/icon.d.ts.map +0 -1
- package/declarations/components/input-builder.d.ts.map +0 -1
- package/declarations/components/list.d.ts.map +0 -1
- package/declarations/components/menu.d.ts.map +0 -1
- package/declarations/components/number-input.d.ts.map +0 -1
- package/declarations/components/page.d.ts.map +0 -1
- package/declarations/components/password-input.d.ts.map +0 -1
- package/declarations/components/phone-input.d.ts.map +0 -1
- package/declarations/components/popover.d.ts.map +0 -1
- package/declarations/components/radio.d.ts.map +0 -1
- package/declarations/components/range-input.d.ts.map +0 -1
- package/declarations/components/section.d.ts.map +0 -1
- package/declarations/components/select.d.ts.map +0 -1
- package/declarations/components/tabs.d.ts.map +0 -1
- package/declarations/components/text-area.d.ts.map +0 -1
- package/declarations/components/text-input.d.ts.map +0 -1
- package/dist/-button-CJL1yb2d.js.map +0 -1
- package/dist/helpers-DApiJrHl.js.map +0 -1
- package/lib/config.js +0 -10
- package/lib/css-modules-plugin.js +0 -43
- package/lib/index.js +0 -30
- package/lib/webpack-asset-loader-plugin.js +0 -23
package/dist/components/form.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
2
|
import { tracked, cached } from '@glimmer/tracking';
|
|
3
3
|
import { assert, warn } from '@ember/debug';
|
|
4
|
-
import {
|
|
4
|
+
import { hash, fn, uniqueId } from '@ember/helper';
|
|
5
5
|
import { on } from '@ember/modifier';
|
|
6
6
|
import { get, set } from '@ember/object';
|
|
7
7
|
import { TrackedAsyncData } from 'ember-async-data';
|
|
@@ -13,7 +13,7 @@ import { precompileTemplate } from '@ember/template-compilation';
|
|
|
13
13
|
import { setComponentTemplate } from '@ember/component';
|
|
14
14
|
import templateOnly from '@ember/component/template-only';
|
|
15
15
|
import Checkbox from './checkbox.js';
|
|
16
|
-
import { b as asBoolean, c as asNumber, d as asString, e as eq } from '../helpers-
|
|
16
|
+
import { b as asBoolean, c as asNumber, d as asString, e as eq } from '../helpers-DS9du02l.js';
|
|
17
17
|
import CurrencyInput from './currency-input.js';
|
|
18
18
|
import DateInput from './date-input.js';
|
|
19
19
|
import EmailInput from './email-input.js';
|
|
@@ -28,62 +28,11 @@ import TextInput from './text-input.js';
|
|
|
28
28
|
import TextArea from './text-area.js';
|
|
29
29
|
import styles$1 from '@hokulea/core/actions.module.css';
|
|
30
30
|
import { d as disabled } from '../disabled-B_FQ0Z51.js';
|
|
31
|
-
import { g, i, n } from 'decorator-transforms/runtime';
|
|
31
|
+
import { g, i, n } from 'decorator-transforms/runtime-esm';
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The subset of properties of DATA, whose keys are strings (and not number or symbol)
|
|
39
|
-
* Only this data is useable in the form
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Returns the type of all keys of DATA, that are also strings. Only strings can be used as field @name
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Generic interface for all validation errors
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Callback used for form level validation
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Callback used for field level validation
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Internal structure to track used fields
|
|
60
|
-
* @private
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* For internal field registration
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Mapper type to construct subset of objects, whose keys are only strings (and not number or symbol)
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
function mergeErrorRecord(...records) {
|
|
73
|
-
const errors = {};
|
|
74
|
-
for (const record of records) {
|
|
75
|
-
if (!record) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
for (const [name, fieldErrors] of Object.entries(record)) {
|
|
79
|
-
const existingFieldErrors = errors[name];
|
|
80
|
-
errors[name] = existingFieldErrors ? [...existingFieldErrors, ...fieldErrors] : fieldErrors;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return errors;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const CaptureEventsModifier = modifier((element, _pos, {
|
|
33
|
+
const CaptureEventsModifier = modifier(
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
35
|
+
(element, _pos, {
|
|
87
36
|
event,
|
|
88
37
|
triggerValidation
|
|
89
38
|
}) => {
|
|
@@ -95,39 +44,63 @@ const CaptureEventsModifier = modifier((element, _pos, {
|
|
|
95
44
|
element.removeEventListener(event, triggerValidation);
|
|
96
45
|
};
|
|
97
46
|
}
|
|
98
|
-
return
|
|
47
|
+
return;
|
|
99
48
|
});
|
|
100
49
|
|
|
50
|
+
// import { modifier } from 'ember-modifier';
|
|
51
|
+
class ManageValidationModifier extends Modifier {
|
|
52
|
+
modify(element, _pos, {
|
|
53
|
+
name,
|
|
54
|
+
showErrorsFor,
|
|
55
|
+
invalid,
|
|
56
|
+
errorMessageId
|
|
57
|
+
}) {
|
|
58
|
+
if (showErrorsFor(name)) {
|
|
59
|
+
element.ariaInvalid = invalid ? 'true' : 'false';
|
|
60
|
+
if (invalid) {
|
|
61
|
+
element.setAttribute('aria-errormessage', errorMessageId);
|
|
62
|
+
} else {
|
|
63
|
+
element.removeAttribute('aria-errormessage');
|
|
64
|
+
}
|
|
65
|
+
if (element.parentElement && 'inputBuilder' in element.parentElement.dataset) {
|
|
66
|
+
element.parentElement.dataset.invalid = invalid ? 'true' : 'false';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
101
73
|
const Description = setComponentTemplate(precompileTemplate("\n <p class={{styles.description}} data-test-description ...attributes>\n {{yield}}\n </p>\n", {
|
|
74
|
+
strictMode: true,
|
|
102
75
|
scope: () => ({
|
|
103
76
|
styles
|
|
104
|
-
})
|
|
105
|
-
strictMode: true
|
|
77
|
+
})
|
|
106
78
|
}), templateOnly());
|
|
107
79
|
|
|
108
80
|
class Errors extends Component {
|
|
109
81
|
static {
|
|
110
82
|
setComponentTemplate(precompileTemplate("\n <div id={{@id}} aria-live=\"assertive\" class={{styles.errors}} ...attributes>\n {{!-- <span><Icon @icon='dismiss-circle' @style='filled' /></span> --}}\n {{#if (has-block)}}\n {{yield @errors}}\n {{else}}\n <div>\n {{#each @errors as |e|}}\n {{#if e.message}}\n <p data-test-error data-test-error-type=\"{{e.type}}\" data-test-error-value=\"{{e.value}}\">{{e.message}}</p>\n {{/if}}\n {{/each}}\n </div>\n {{/if}}\n </div>\n ", {
|
|
83
|
+
strictMode: true,
|
|
111
84
|
scope: () => ({
|
|
112
85
|
styles
|
|
113
|
-
})
|
|
114
|
-
strictMode: true
|
|
86
|
+
})
|
|
115
87
|
}), this);
|
|
116
88
|
}
|
|
117
89
|
}
|
|
118
90
|
|
|
119
|
-
const Label = setComponentTemplate(precompileTemplate("\n {{#let (if @element @element (element \"label\")) as |Element|}}\n
|
|
91
|
+
const Label = setComponentTemplate(precompileTemplate("\n {{#let (if @element @element (element \"label\")) as |Element|}}\n <Element class={{styles.label}} data-test-label ...attributes>\n {{yield}}\n </Element>\n {{/let}}\n", {
|
|
92
|
+
strictMode: true,
|
|
120
93
|
scope: () => ({
|
|
121
94
|
element,
|
|
122
95
|
styles
|
|
123
|
-
})
|
|
124
|
-
strictMode: true
|
|
96
|
+
})
|
|
125
97
|
}), templateOnly());
|
|
126
98
|
|
|
127
99
|
class Field extends Component {
|
|
128
100
|
// Label = this.args.labelComponent ?? Label;
|
|
129
|
-
|
|
130
|
-
|
|
101
|
+
ManagaValidationModifier = ManageValidationModifier;
|
|
102
|
+
constructor(owner, args) {
|
|
103
|
+
super(owner, args);
|
|
131
104
|
assert('Nested property paths in @name are not supported.', typeof this.args.name !== 'string' || !this.args.name.includes('.'));
|
|
132
105
|
this.args.registerField(this.args.name, {
|
|
133
106
|
validate: this.args.validate
|
|
@@ -149,22 +122,29 @@ class Field extends Component {
|
|
|
149
122
|
return this.errors !== undefined;
|
|
150
123
|
}
|
|
151
124
|
get valueAsString() {
|
|
152
|
-
assert(`Only string values are expected for ${String(this.args.name)}, but you passed ${typeof this.value}`,
|
|
125
|
+
assert(`Only string values are expected for ${String(this.args.name)}, but you passed ${typeof this.value}`,
|
|
126
|
+
// eslint-disable-next-line unicorn/no-typeof-undefined
|
|
127
|
+
typeof this.value === 'undefined' || typeof this.value === 'string');
|
|
153
128
|
return this.value;
|
|
154
129
|
}
|
|
155
130
|
get valueAsStringOrNumber() {
|
|
156
|
-
assert(`Only string or number values are expected for ${String(this.args.name)}, but you passed ${typeof this.value}`,
|
|
131
|
+
assert(`Only string or number values are expected for ${String(this.args.name)}, but you passed ${typeof this.value}`,
|
|
132
|
+
// eslint-disable-next-line unicorn/no-typeof-undefined
|
|
133
|
+
typeof this.value === 'undefined' || typeof this.value === 'string' || typeof this.value === 'number');
|
|
157
134
|
return this.value;
|
|
158
135
|
}
|
|
159
136
|
get valueAsBoolean() {
|
|
160
|
-
assert(`Only boolean values are expected for ${String(this.args.name)}, but you passed ${typeof this.value}`,
|
|
137
|
+
assert(`Only boolean values are expected for ${String(this.args.name)}, but you passed ${typeof this.value}`,
|
|
138
|
+
// eslint-disable-next-line unicorn/no-typeof-undefined
|
|
139
|
+
typeof this.value === 'undefined' || typeof this.value === 'boolean');
|
|
161
140
|
return this.value;
|
|
162
141
|
}
|
|
163
|
-
setValue =
|
|
164
|
-
this.args.set(this.args.name,
|
|
142
|
+
setValue = value => {
|
|
143
|
+
this.args.set(this.args.name, value);
|
|
165
144
|
};
|
|
166
145
|
static {
|
|
167
|
-
setComponentTemplate(precompileTemplate("\n {{#let (uniqueId) (uniqueId) (fn @triggerValidationFor @name) (if @element @element (element \"div\")) as |fieldId errorId triggerValidation Element|}}\n <Element class={{styles.field}} data-test-field={{@name}}>\n {{#if @label}}\n {{#let (if @labelComponent @labelComponent Label) as |L|}}\n <L for={{unless @labelComponent fieldId}}>{{@label}}</L>\n {{/let}}\n {{/if}}\n\n {{#if @description}}\n <Description>{{@description}}</Description>\n {{/if}}\n\n {{yield (hash value=this.value setValue=this.setValue id=fieldId errorId=errorId invalid=this.invalid rawErrors=this.errors triggerValidation=triggerValidation captureEvents=(modifier CaptureEventsModifier event=(if this.invalid @fieldRevalidationEvent @fieldValidationEvent) triggerValidation=triggerValidation) manageValidation=(modifier
|
|
146
|
+
setComponentTemplate(precompileTemplate("\n {{#let (uniqueId) (uniqueId) (fn @triggerValidationFor @name) (if @element @element (element \"div\")) as |fieldId errorId triggerValidation Element|}}\n <Element class={{styles.field}} data-test-field={{@name}}>\n {{#if @label}}\n {{#let (if @labelComponent @labelComponent Label) as |L|}}\n <L for={{unless @labelComponent fieldId}}>{{@label}}</L>\n {{/let}}\n {{/if}}\n\n {{#if @description}}\n <Description>{{@description}}</Description>\n {{/if}}\n\n {{yield (hash value=this.value setValue=this.setValue id=fieldId errorId=errorId invalid=this.invalid rawErrors=this.errors triggerValidation=triggerValidation captureEvents=(modifier CaptureEventsModifier event=(if this.invalid @fieldRevalidationEvent @fieldValidationEvent) triggerValidation=triggerValidation) manageValidation=(modifier this.ManagaValidationModifier invalid=this.invalid errorMessageId=errorId name=@name showErrorsFor=@showErrorsFor))}}\n\n {{#if this.errors}}\n <Errors @id={{errorId}} @errors={{this.errors}} />\n {{/if}}\n </Element>\n {{/let}}\n ", {
|
|
147
|
+
strictMode: true,
|
|
168
148
|
scope: () => ({
|
|
169
149
|
uniqueId,
|
|
170
150
|
fn,
|
|
@@ -175,114 +155,113 @@ class Field extends Component {
|
|
|
175
155
|
hash,
|
|
176
156
|
CaptureEventsModifier,
|
|
177
157
|
Errors
|
|
178
|
-
})
|
|
179
|
-
strictMode: true
|
|
158
|
+
})
|
|
180
159
|
}), this);
|
|
181
160
|
}
|
|
182
161
|
}
|
|
183
162
|
|
|
184
163
|
class RadioField extends Component {
|
|
185
164
|
Field = this.args.Field;
|
|
186
|
-
setBooleanValue =
|
|
187
|
-
return
|
|
165
|
+
setBooleanValue = setValue => {
|
|
166
|
+
return value => setValue(value);
|
|
188
167
|
};
|
|
189
168
|
static {
|
|
190
|
-
setComponentTemplate(precompileTemplate("\n <this.Field @label @name={{@name}} @validate={{@validate}} as |f|>\n <div class={{styles.choices}}>\n <div class={{styles.choice}}>\n <span>\n <Checkbox @value={{asBoolean f.value}} @update={{this.setBooleanValue f.setValue}} @disabled={{@disabled}} id={{f.id}} name={{@name}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </span>\n\n <div>\n <Label for={{f.id}}>{{@label}}</Label>\n\n {{#if @description}}\n <Description>{{@description}}</Description>\n {{/if}}\n </div>\n </div>\n </div>\n </this.Field>\n ", {
|
|
169
|
+
setComponentTemplate(precompileTemplate("\n <this.Field @label=\"\" @name={{@name}} @validate={{@validate}} as |f|>\n <div class={{styles.choices}}>\n <div class={{styles.choice}}>\n <span>\n <Checkbox @value={{asBoolean f.value}} @update={{this.setBooleanValue f.setValue}} @disabled={{@disabled}} id={{f.id}} name={{@name}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </span>\n\n <div>\n <Label for={{f.id}}>{{@label}}</Label>\n\n {{#if @description}}\n <Description>{{@description}}</Description>\n {{/if}}\n </div>\n </div>\n </div>\n </this.Field>\n ", {
|
|
170
|
+
strictMode: true,
|
|
191
171
|
scope: () => ({
|
|
192
172
|
styles,
|
|
193
173
|
Checkbox,
|
|
194
174
|
asBoolean,
|
|
195
175
|
Label,
|
|
196
176
|
Description
|
|
197
|
-
})
|
|
198
|
-
strictMode: true
|
|
177
|
+
})
|
|
199
178
|
}), this);
|
|
200
179
|
}
|
|
201
180
|
}
|
|
202
181
|
|
|
203
182
|
class CurrencyField extends Component {
|
|
204
183
|
Field = this.args.Field;
|
|
205
|
-
setNumberValue =
|
|
206
|
-
return
|
|
184
|
+
setNumberValue = setValue => {
|
|
185
|
+
return value => setValue(value);
|
|
207
186
|
};
|
|
208
187
|
static {
|
|
209
188
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <CurrencyInput @value={{asNumber f.value}} @update={{this.setNumberValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
189
|
+
strictMode: true,
|
|
210
190
|
scope: () => ({
|
|
211
191
|
CurrencyInput,
|
|
212
192
|
asNumber
|
|
213
|
-
})
|
|
214
|
-
strictMode: true
|
|
193
|
+
})
|
|
215
194
|
}), this);
|
|
216
195
|
}
|
|
217
196
|
}
|
|
218
197
|
|
|
219
198
|
class DateField extends Component {
|
|
220
199
|
Field = this.args.Field;
|
|
221
|
-
setStringValue =
|
|
222
|
-
return
|
|
200
|
+
setStringValue = setValue => {
|
|
201
|
+
return value => setValue(value);
|
|
223
202
|
};
|
|
224
203
|
static {
|
|
225
204
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <DateInput @value={{asString f.value}} @update={{this.setStringValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
205
|
+
strictMode: true,
|
|
226
206
|
scope: () => ({
|
|
227
207
|
DateInput,
|
|
228
208
|
asString
|
|
229
|
-
})
|
|
230
|
-
strictMode: true
|
|
209
|
+
})
|
|
231
210
|
}), this);
|
|
232
211
|
}
|
|
233
212
|
}
|
|
234
213
|
|
|
235
214
|
class EmailField extends Component {
|
|
236
215
|
Field = this.args.Field;
|
|
237
|
-
setStringValue =
|
|
238
|
-
return
|
|
216
|
+
setStringValue = setValue => {
|
|
217
|
+
return value => setValue(value);
|
|
239
218
|
};
|
|
240
219
|
static {
|
|
241
220
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <EmailInput @value={{asString f.value}} @update={{this.setStringValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
221
|
+
strictMode: true,
|
|
242
222
|
scope: () => ({
|
|
243
223
|
EmailInput,
|
|
244
224
|
asString
|
|
245
|
-
})
|
|
246
|
-
strictMode: true
|
|
225
|
+
})
|
|
247
226
|
}), this);
|
|
248
227
|
}
|
|
249
228
|
}
|
|
250
229
|
|
|
251
230
|
const ListLabel = setComponentTemplate(precompileTemplate("\n <Label @element={{element \"span\"}} id={{@id}}>{{yield}}</Label>\n", {
|
|
231
|
+
strictMode: true,
|
|
252
232
|
scope: () => ({
|
|
253
233
|
Label,
|
|
254
234
|
element
|
|
255
|
-
})
|
|
256
|
-
strictMode: true
|
|
235
|
+
})
|
|
257
236
|
}), templateOnly());
|
|
258
237
|
class ListField extends Component {
|
|
259
238
|
Field = this.args.Field;
|
|
260
239
|
List = List;
|
|
261
|
-
setValue =
|
|
262
|
-
return
|
|
240
|
+
setValue = setValue => {
|
|
241
|
+
return value => setValue(value);
|
|
263
242
|
};
|
|
264
|
-
asValue =
|
|
243
|
+
asValue = value => value;
|
|
265
244
|
static {
|
|
266
|
-
setComponentTemplate(precompileTemplate("\n {{#let (uniqueId) as |labelId|}}\n <this.Field @name={{@name}} @label={{@label}} @labelComponent={{component ListLabel id=labelId}} @description={{@description}} @validate={{@validate}} as |f|>\n <this.List @value={{this.asValue f.value}} @update={{this.setValue f.setValue}} @disabled={{@disabled}} name={{@name}} aria-labelledby={{labelId}} {{f.manageValidation}} {{f.captureEvents}} ...attributes as |s|>\n {{yield s}}\n </this.List>\n </this.Field>\n {{/let}}\n ", {
|
|
245
|
+
setComponentTemplate(precompileTemplate("\n {{#let (uniqueId) as |labelId|}}\n <this.Field @name={{@name}} @label={{@label}} @labelComponent={{component ListLabel id=labelId}} @description={{@description}} @validate={{@validate}} as |f|>\n <this.List @value={{this.asValue f.value}} @update={{this.setValue f.setValue}} @disabled={{@disabled}} {{!-- name={{@name}} --}} aria-labelledby={{labelId}} {{f.manageValidation}} {{f.captureEvents}} ...attributes as |s|>\n {{yield s}}\n </this.List>\n </this.Field>\n {{/let}}\n ", {
|
|
246
|
+
strictMode: true,
|
|
267
247
|
scope: () => ({
|
|
268
248
|
uniqueId,
|
|
269
249
|
ListLabel
|
|
270
|
-
})
|
|
271
|
-
strictMode: true
|
|
250
|
+
})
|
|
272
251
|
}), this);
|
|
273
252
|
}
|
|
274
253
|
}
|
|
275
254
|
|
|
276
255
|
let Option$1 = class Option extends Component {
|
|
277
|
-
select =
|
|
278
|
-
if (
|
|
256
|
+
select = checked => {
|
|
257
|
+
if (checked) {
|
|
279
258
|
this.args.field.setValue([...(this.args.field.value ?? []), this.args.value]);
|
|
280
259
|
} else {
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
if (Array.isArray(
|
|
284
|
-
|
|
285
|
-
this.args.field.setValue(
|
|
260
|
+
const values = this.args.field.value;
|
|
261
|
+
const index = this.args.field.value?.indexOf(this.args.value);
|
|
262
|
+
if (Array.isArray(values) && index) {
|
|
263
|
+
values.splice(index, 1);
|
|
264
|
+
this.args.field.setValue(values);
|
|
286
265
|
}
|
|
287
266
|
}
|
|
288
267
|
};
|
|
@@ -291,122 +270,123 @@ let Option$1 = class Option extends Component {
|
|
|
291
270
|
}
|
|
292
271
|
static {
|
|
293
272
|
setComponentTemplate(precompileTemplate("\n {{#let (uniqueId) as |id|}}\n <div class={{styles.choice}} data-test-option>\n <span>\n <Checkbox @value={{this.checked}} @update={{this.select}} @disabled={{@disabled}} id={{id}} name={{@name}} value={{@value}} {{@field.manageValidation}} {{@field.captureEvents}} ...attributes />\n </span>\n\n <div>\n <Label for={{id}}>{{@label}}</Label>\n\n {{#if @description}}\n <Description>{{@description}}</Description>\n {{/if}}\n\n {{yield}}\n </div>\n </div>\n {{/let}}\n ", {
|
|
273
|
+
strictMode: true,
|
|
294
274
|
scope: () => ({
|
|
295
275
|
uniqueId,
|
|
296
276
|
styles,
|
|
297
277
|
Checkbox,
|
|
298
278
|
Label,
|
|
299
279
|
Description
|
|
300
|
-
})
|
|
301
|
-
strictMode: true
|
|
280
|
+
})
|
|
302
281
|
}), this);
|
|
303
282
|
}
|
|
304
283
|
};
|
|
305
284
|
class MultipleChoiceField extends Component {
|
|
306
285
|
Field = this.args.Field;
|
|
307
286
|
Option = Option$1;
|
|
308
|
-
asMultiField =
|
|
309
|
-
return
|
|
287
|
+
asMultiField = field => {
|
|
288
|
+
return field;
|
|
310
289
|
};
|
|
311
290
|
static {
|
|
312
291
|
setComponentTemplate(precompileTemplate("\n <this.Field @element={{element \"fieldset\"}} @labelComponent={{component Label element=(element \"legend\")}} @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <div class={{styles.choices}} data-test-choices>\n {{yield (hash Option=(component this.Option field=(this.asMultiField f) name=@name disabled=@disabled))}}\n </div>\n </this.Field>\n ", {
|
|
292
|
+
strictMode: true,
|
|
313
293
|
scope: () => ({
|
|
314
294
|
element,
|
|
315
295
|
Label,
|
|
316
296
|
styles,
|
|
317
297
|
hash
|
|
318
|
-
})
|
|
319
|
-
strictMode: true
|
|
298
|
+
})
|
|
320
299
|
}), this);
|
|
321
300
|
}
|
|
322
301
|
}
|
|
323
302
|
|
|
324
303
|
class NumberField extends Component {
|
|
325
304
|
Field = this.args.Field;
|
|
326
|
-
setNumberValue =
|
|
327
|
-
return
|
|
305
|
+
setNumberValue = setValue => {
|
|
306
|
+
return value => setValue(value);
|
|
328
307
|
};
|
|
329
308
|
static {
|
|
330
309
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <NumberInput @value={{asNumber f.value}} @update={{this.setNumberValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
310
|
+
strictMode: true,
|
|
331
311
|
scope: () => ({
|
|
332
312
|
NumberInput,
|
|
333
313
|
asNumber
|
|
334
|
-
})
|
|
335
|
-
strictMode: true
|
|
314
|
+
})
|
|
336
315
|
}), this);
|
|
337
316
|
}
|
|
338
317
|
}
|
|
339
318
|
|
|
340
319
|
class PasswordField extends Component {
|
|
341
320
|
Field = this.args.Field;
|
|
342
|
-
setStringValue =
|
|
343
|
-
return
|
|
321
|
+
setStringValue = setValue => {
|
|
322
|
+
return value => setValue(value);
|
|
344
323
|
};
|
|
345
324
|
static {
|
|
346
325
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <PasswordInput @value={{asString f.value}} @update={{this.setStringValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
326
|
+
strictMode: true,
|
|
347
327
|
scope: () => ({
|
|
348
328
|
PasswordInput,
|
|
349
329
|
asString
|
|
350
|
-
})
|
|
351
|
-
strictMode: true
|
|
330
|
+
})
|
|
352
331
|
}), this);
|
|
353
332
|
}
|
|
354
333
|
}
|
|
355
334
|
|
|
356
335
|
class PhoneField extends Component {
|
|
357
336
|
Field = this.args.Field;
|
|
358
|
-
setStringValue =
|
|
359
|
-
return
|
|
337
|
+
setStringValue = setValue => {
|
|
338
|
+
return value => setValue(value);
|
|
360
339
|
};
|
|
361
340
|
static {
|
|
362
341
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <PhoneInput @value={{asString f.value}} @update={{this.setStringValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
342
|
+
strictMode: true,
|
|
363
343
|
scope: () => ({
|
|
364
344
|
PhoneInput,
|
|
365
345
|
asString
|
|
366
|
-
})
|
|
367
|
-
strictMode: true
|
|
346
|
+
})
|
|
368
347
|
}), this);
|
|
369
348
|
}
|
|
370
349
|
}
|
|
371
350
|
|
|
372
351
|
class RangeField extends Component {
|
|
373
352
|
Field = this.args.Field;
|
|
374
|
-
setNumberValue =
|
|
375
|
-
return
|
|
353
|
+
setNumberValue = setValue => {
|
|
354
|
+
return value => setValue(value);
|
|
376
355
|
};
|
|
377
356
|
static {
|
|
378
357
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <RangeInput @value={{asNumber f.value}} @update={{this.setNumberValue f.setValue}} @disabled={{@disabled}} @orientation={{@orientation}} @min={{@min}} @max={{@max}} @step={{@step}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
358
|
+
strictMode: true,
|
|
379
359
|
scope: () => ({
|
|
380
360
|
RangeInput,
|
|
381
361
|
asNumber
|
|
382
|
-
})
|
|
383
|
-
strictMode: true
|
|
362
|
+
})
|
|
384
363
|
}), this);
|
|
385
364
|
}
|
|
386
365
|
}
|
|
387
366
|
|
|
388
367
|
class SelectField extends Component {
|
|
389
368
|
Field = this.args.Field;
|
|
390
|
-
setValue =
|
|
391
|
-
return
|
|
369
|
+
setValue = setValue => {
|
|
370
|
+
return value => setValue(value);
|
|
392
371
|
};
|
|
393
372
|
static {
|
|
394
373
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <Select @value={{asString f.value}} @update={{this.setValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes as |s|>\n {{yield s}}\n </Select>\n </this.Field>\n ", {
|
|
374
|
+
strictMode: true,
|
|
395
375
|
scope: () => ({
|
|
396
376
|
Select,
|
|
397
377
|
asString
|
|
398
|
-
})
|
|
399
|
-
strictMode: true
|
|
378
|
+
})
|
|
400
379
|
}), this);
|
|
401
380
|
}
|
|
402
381
|
}
|
|
403
382
|
|
|
404
|
-
|
|
383
|
+
class Option extends Component {
|
|
405
384
|
select = () => {
|
|
406
385
|
this.args.field.setValue(this.args.value);
|
|
407
386
|
};
|
|
408
387
|
static {
|
|
409
388
|
setComponentTemplate(precompileTemplate("\n {{#let (uniqueId) as |id|}}\n <div class={{styles.choice}} data-test-option>\n <span>\n <Radio @value={{eq @field.value @value}} @update={{this.select}} @disabled={{@disabled}} id={{id}} name={{@name}} value={{@value}} {{@field.manageValidation}} {{@field.captureEvents}} ...attributes />\n </span>\n\n <div>\n <Label for={{id}}>{{@label}}</Label>\n\n {{#if @description}}\n <Description>{{@description}}</Description>\n {{/if}}\n\n {{yield}}\n </div>\n </div>\n {{/let}}\n ", {
|
|
389
|
+
strictMode: true,
|
|
410
390
|
scope: () => ({
|
|
411
391
|
uniqueId,
|
|
412
392
|
styles,
|
|
@@ -414,117 +394,133 @@ let Option = class Option extends Component {
|
|
|
414
394
|
eq,
|
|
415
395
|
Label,
|
|
416
396
|
Description
|
|
417
|
-
})
|
|
418
|
-
strictMode: true
|
|
397
|
+
})
|
|
419
398
|
}), this);
|
|
420
399
|
}
|
|
421
|
-
}
|
|
400
|
+
}
|
|
422
401
|
class SingularChoiceField extends Component {
|
|
423
402
|
Field = this.args.Field;
|
|
424
403
|
Option = Option;
|
|
425
404
|
static {
|
|
426
405
|
setComponentTemplate(precompileTemplate("\n <this.Field @element={{element \"fieldset\"}} @labelComponent={{component Label element=(element \"legend\")}} @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <div class={{styles.choices}} data-test-choices>\n {{yield (hash Option=(component this.Option field=f name=@name disabled=@disabled))}}\n </div>\n </this.Field>\n ", {
|
|
406
|
+
strictMode: true,
|
|
427
407
|
scope: () => ({
|
|
428
408
|
element,
|
|
429
409
|
Label,
|
|
430
410
|
styles,
|
|
431
411
|
hash
|
|
432
|
-
})
|
|
433
|
-
strictMode: true
|
|
412
|
+
})
|
|
434
413
|
}), this);
|
|
435
414
|
}
|
|
436
415
|
}
|
|
437
416
|
|
|
438
417
|
let TextField$1 = class TextField extends Component {
|
|
439
418
|
Field = this.args.Field;
|
|
440
|
-
setStringValue =
|
|
441
|
-
return
|
|
419
|
+
setStringValue = setValue => {
|
|
420
|
+
return value => setValue(value);
|
|
442
421
|
};
|
|
443
422
|
static {
|
|
444
423
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <TextInput @value={{asString f.value}} @update={{this.setStringValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
424
|
+
strictMode: true,
|
|
445
425
|
scope: () => ({
|
|
446
426
|
TextInput,
|
|
447
427
|
asString
|
|
448
|
-
})
|
|
449
|
-
strictMode: true
|
|
428
|
+
})
|
|
450
429
|
}), this);
|
|
451
430
|
}
|
|
452
431
|
};
|
|
453
432
|
|
|
454
433
|
class TextField extends Component {
|
|
455
434
|
Field = this.args.Field;
|
|
456
|
-
setStringValue =
|
|
457
|
-
return
|
|
435
|
+
setStringValue = setValue => {
|
|
436
|
+
return value => setValue(value);
|
|
458
437
|
};
|
|
459
438
|
static {
|
|
460
439
|
setComponentTemplate(precompileTemplate("\n <this.Field @name={{@name}} @label={{@label}} @description={{@description}} @validate={{@validate}} as |f|>\n <TextArea @value={{asString f.value}} @update={{this.setStringValue f.setValue}} @disabled={{@disabled}} name={{@name}} id={{f.id}} {{f.manageValidation}} {{f.captureEvents}} ...attributes />\n </this.Field>\n ", {
|
|
440
|
+
strictMode: true,
|
|
461
441
|
scope: () => ({
|
|
462
442
|
TextArea,
|
|
463
443
|
asString
|
|
464
|
-
})
|
|
465
|
-
strictMode: true
|
|
444
|
+
})
|
|
466
445
|
}), this);
|
|
467
446
|
}
|
|
468
447
|
}
|
|
469
448
|
|
|
470
449
|
const Reset = setComponentTemplate(precompileTemplate("\n <button type=\"reset\" class={{styles.button}} data-intent={{if @intent @intent \"action\"}} data-importance={{if @importance @importance \"supreme\"}} data-spacing={{@spacing}} {{disabled when=(if @disabled @disabled false)}} data-test-button ...attributes>\n {{#if (has-block \"before\")}}\n <span data-test-button=\"before\">\n {{yield to=\"before\"}}\n </span>\n {{/if}}\n\n <span data-test-button=\"label\">\n {{#if (has-block \"label\")}}\n {{yield to=\"label\"}}\n {{/if}}\n\n {{#if (has-block)}}\n {{yield}}\n {{/if}}\n </span>\n\n {{#if (has-block \"after\")}}\n <span data-test-button=\"after\">\n {{yield to=\"after\"}}\n </span>\n {{/if}}\n </button>\n", {
|
|
450
|
+
strictMode: true,
|
|
471
451
|
scope: () => ({
|
|
472
452
|
styles: styles$1,
|
|
473
453
|
disabled
|
|
474
|
-
})
|
|
475
|
-
strictMode: true
|
|
454
|
+
})
|
|
476
455
|
}), templateOnly());
|
|
477
456
|
|
|
478
457
|
const Submit = setComponentTemplate(precompileTemplate("\n <button type=\"submit\" class={{styles.button}} data-intent={{if @intent @intent \"action\"}} data-importance={{if @importance @importance \"supreme\"}} data-spacing={{@spacing}} {{disabled when=(if @disabled @disabled false)}} data-test-button ...attributes>\n {{#if (has-block \"before\")}}\n <span data-test-button=\"before\">\n {{yield to=\"before\"}}\n </span>\n {{/if}}\n\n <span data-test-button=\"label\">\n {{#if (has-block \"label\")}}\n {{yield to=\"label\"}}\n {{/if}}\n\n {{#if (has-block)}}\n {{yield}}\n {{/if}}\n </span>\n\n {{#if (has-block \"after\")}}\n <span data-test-button=\"after\">\n {{yield to=\"after\"}}\n </span>\n {{/if}}\n </button>\n", {
|
|
458
|
+
strictMode: true,
|
|
479
459
|
scope: () => ({
|
|
480
460
|
styles: styles$1,
|
|
481
461
|
disabled
|
|
482
|
-
})
|
|
483
|
-
strictMode: true
|
|
462
|
+
})
|
|
484
463
|
}), templateOnly());
|
|
485
464
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
465
|
+
/**
|
|
466
|
+
* What the user can pass as @data
|
|
467
|
+
*/
|
|
489
468
|
|
|
490
|
-
|
|
469
|
+
/**
|
|
470
|
+
* The subset of properties of DATA, whose keys are strings (and not number or symbol)
|
|
471
|
+
* Only this data is useable in the form
|
|
472
|
+
*/
|
|
491
473
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
// Positional: Positional;
|
|
496
|
-
// Named: RenderOptions;
|
|
497
|
-
// };
|
|
498
|
-
// }
|
|
474
|
+
/**
|
|
475
|
+
* Returns the type of all keys of DATA, that are also strings. Only strings can be used as field @name
|
|
476
|
+
*/
|
|
499
477
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
478
|
+
/**
|
|
479
|
+
* Generic interface for all validation errors
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Callback used for form level validation
|
|
484
|
+
*/
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Callback used for field level validation
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Internal structure to track used fields
|
|
492
|
+
* @private
|
|
493
|
+
*/
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* For internal field registration
|
|
497
|
+
* @private
|
|
498
|
+
*/
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Mapper type to construct subset of objects, whose keys are only strings (and not number or symbol)
|
|
502
|
+
*/
|
|
503
|
+
|
|
504
|
+
function mergeErrorRecord(...records) {
|
|
505
|
+
const errors = {};
|
|
506
|
+
for (const record of records) {
|
|
507
|
+
if (!record) {
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
for (const [name, fieldErrors] of Object.entries(record)) {
|
|
511
|
+
const existingFieldErrors = errors[name];
|
|
512
|
+
errors[name] = existingFieldErrors ? [...existingFieldErrors, ...fieldErrors] : fieldErrors;
|
|
517
513
|
}
|
|
518
|
-
return undefined;
|
|
519
514
|
}
|
|
515
|
+
return errors;
|
|
520
516
|
}
|
|
521
517
|
|
|
522
518
|
/**
|
|
523
519
|
* This internal data structure maintains information about each field that is registered to the form by `registerField`.
|
|
524
520
|
*/
|
|
525
|
-
|
|
526
|
-
constructor(
|
|
527
|
-
this.validate =
|
|
521
|
+
class FieldData {
|
|
522
|
+
constructor(fieldRegistration) {
|
|
523
|
+
this.validate = fieldRegistration.validate;
|
|
528
524
|
}
|
|
529
525
|
/**
|
|
530
526
|
* tracked state that enabled a dynamic validation of a field *before* the whole form is submitted, e.g. by `@validateOn="blur" and the blur event being triggered for that particular field.
|
|
@@ -539,8 +535,7 @@ let FieldData = class FieldData {
|
|
|
539
535
|
* The *field* level validation callback passed to the field as in `<form.field @name="foo" @validate={{this.validateCallback}}>`
|
|
540
536
|
*/
|
|
541
537
|
validate;
|
|
542
|
-
}
|
|
543
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
538
|
+
}
|
|
544
539
|
class Form extends Component {
|
|
545
540
|
Field = Field;
|
|
546
541
|
CheckboxField = RadioField;
|
|
@@ -557,32 +552,31 @@ class Form extends Component {
|
|
|
557
552
|
SingularChoiceField = SingularChoiceField;
|
|
558
553
|
TextField = TextField$1;
|
|
559
554
|
TextAreaField = TextField;
|
|
560
|
-
ManagaValidationModifier = ManageValidationModifier;
|
|
561
555
|
formElement;
|
|
562
|
-
registerForm = modifier((
|
|
563
|
-
this.formElement =
|
|
556
|
+
registerForm = modifier((el, _p) => {
|
|
557
|
+
this.formElement = el;
|
|
564
558
|
});
|
|
565
|
-
submit = async
|
|
566
|
-
|
|
559
|
+
submit = async e => {
|
|
560
|
+
e?.preventDefault();
|
|
567
561
|
await this.validateWithState();
|
|
568
562
|
this.showAllValidations = true;
|
|
569
|
-
if (
|
|
570
|
-
if (this.args.submit) {
|
|
571
|
-
this.submissionState = new TrackedAsyncData(this.args.submit(this.effectiveData));
|
|
572
|
-
}
|
|
573
|
-
} else {
|
|
563
|
+
if (this.validationErrorsExist) {
|
|
574
564
|
assert('Validation errors expected to be present. If you see this, please report it as a bug to ember-headless-form!',
|
|
575
565
|
// with optional chaining this leads to a NPE
|
|
576
566
|
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
577
567
|
this.validationState && this.validationState.isResolved);
|
|
578
568
|
this.args.invalidated?.(this.effectiveData, this.validationState.value);
|
|
569
|
+
} else {
|
|
570
|
+
if (this.args.submit) {
|
|
571
|
+
this.submissionState = new TrackedAsyncData(this.args.submit(this.effectiveData));
|
|
572
|
+
}
|
|
579
573
|
}
|
|
580
574
|
};
|
|
581
|
-
reset =
|
|
582
|
-
|
|
583
|
-
for (const
|
|
575
|
+
reset = e => {
|
|
576
|
+
e?.preventDefault();
|
|
577
|
+
for (const key of Object.keys(this.internalData)) {
|
|
584
578
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
585
|
-
delete this.internalData[
|
|
579
|
+
delete this.internalData[key];
|
|
586
580
|
}
|
|
587
581
|
this.validationState = undefined;
|
|
588
582
|
this.submissionState = undefined;
|
|
@@ -592,35 +586,34 @@ class Form extends Component {
|
|
|
592
586
|
*/
|
|
593
587
|
internalData = new TrackedObject({});
|
|
594
588
|
get effectiveData() {
|
|
595
|
-
|
|
596
|
-
const obj1 = this.args.data ?? {};
|
|
589
|
+
const obj = this.args.data ?? {};
|
|
597
590
|
if (this.args.dataMode === 'mutable') {
|
|
598
|
-
return
|
|
591
|
+
return obj;
|
|
599
592
|
}
|
|
600
593
|
const {
|
|
601
|
-
internalData
|
|
594
|
+
internalData
|
|
602
595
|
} = this;
|
|
603
|
-
return new Proxy(
|
|
604
|
-
get(
|
|
605
|
-
return
|
|
596
|
+
return new Proxy(obj, {
|
|
597
|
+
get(target, prop) {
|
|
598
|
+
return prop in internalData ? internalData[prop] : Reflect.get(target, prop);
|
|
606
599
|
},
|
|
607
|
-
set(
|
|
608
|
-
return Reflect.set(
|
|
600
|
+
set(_target, property, value) {
|
|
601
|
+
return Reflect.set(internalData, property, value);
|
|
609
602
|
},
|
|
610
|
-
has(
|
|
611
|
-
return
|
|
603
|
+
has(target, prop) {
|
|
604
|
+
return prop in internalData ? true : Reflect.has(target, prop);
|
|
612
605
|
},
|
|
613
|
-
getOwnPropertyDescriptor(
|
|
614
|
-
return Reflect.getOwnPropertyDescriptor(
|
|
606
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
607
|
+
return Reflect.getOwnPropertyDescriptor(prop in internalData ? internalData : target, prop);
|
|
615
608
|
},
|
|
616
|
-
ownKeys(
|
|
617
|
-
return [...Reflect.ownKeys(
|
|
618
|
-
.filter((
|
|
609
|
+
ownKeys(target) {
|
|
610
|
+
return [...Reflect.ownKeys(target), ...Reflect.ownKeys(internalData)] // return only unique values
|
|
611
|
+
.filter((value, index, array) => array.indexOf(value) === index);
|
|
619
612
|
},
|
|
620
|
-
deleteProperty(
|
|
621
|
-
if (
|
|
613
|
+
deleteProperty(_target, prop) {
|
|
614
|
+
if (prop in internalData) {
|
|
622
615
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
623
|
-
delete
|
|
616
|
+
delete internalData[prop];
|
|
624
617
|
}
|
|
625
618
|
return true;
|
|
626
619
|
}
|
|
@@ -630,16 +623,16 @@ class Form extends Component {
|
|
|
630
623
|
n(this.prototype, "effectiveData", [cached]);
|
|
631
624
|
}
|
|
632
625
|
fields = new Map();
|
|
633
|
-
registerField = (
|
|
634
|
-
assert(`You passed @name="${String(
|
|
635
|
-
this.fields.set(
|
|
626
|
+
registerField = (name, field) => {
|
|
627
|
+
assert(`You passed @name="${String(name)}" to the form field, but this is already in use. Names of form fields must be unique!`, !this.fields.has(name));
|
|
628
|
+
this.fields.set(name, new FieldData(field));
|
|
636
629
|
};
|
|
637
|
-
unregisterField =
|
|
638
|
-
this.fields.delete(
|
|
630
|
+
unregisterField = name => {
|
|
631
|
+
this.fields.delete(name);
|
|
639
632
|
};
|
|
640
|
-
set = (
|
|
633
|
+
set = (key, value) => {
|
|
641
634
|
// when @mutableData is set, our effectiveData is something we don't control, i.e. might require old-school set() to be on the safe side
|
|
642
|
-
set(this.effectiveData,
|
|
635
|
+
set(this.effectiveData, key, value);
|
|
643
636
|
// console.log('internalData', this.internalData);
|
|
644
637
|
};
|
|
645
638
|
static {
|
|
@@ -670,79 +663,79 @@ class Form extends Component {
|
|
|
670
663
|
*/
|
|
671
664
|
get fieldValidationEvent() {
|
|
672
665
|
const {
|
|
673
|
-
validateOn
|
|
666
|
+
validateOn
|
|
674
667
|
} = this;
|
|
675
|
-
return
|
|
668
|
+
return validateOn === 'submit' ? undefined : validateOn;
|
|
676
669
|
}
|
|
677
670
|
/**
|
|
678
671
|
* Return the event type that will be listened on for dynamic *re*validation, i.e. updating the validation status of a field that has been previously marked as invalid
|
|
679
672
|
*/
|
|
680
673
|
get fieldRevalidationEvent() {
|
|
681
674
|
const {
|
|
682
|
-
validateOn
|
|
683
|
-
revalidateOn
|
|
675
|
+
validateOn,
|
|
676
|
+
revalidateOn
|
|
684
677
|
} = this;
|
|
685
|
-
return
|
|
678
|
+
return revalidateOn === 'submit' ? undefined : validateOn === 'input' || validateOn === 'change' && revalidateOn === 'focusout' || validateOn === revalidateOn ? undefined : revalidateOn;
|
|
686
679
|
}
|
|
687
680
|
/**
|
|
688
681
|
* Return true if validation has happened (by submitting or by an `@validateOn` event being triggered) and at least one field is invalid
|
|
689
682
|
*/
|
|
690
683
|
get validationErrorsExist() {
|
|
691
684
|
const {
|
|
692
|
-
validationState
|
|
685
|
+
validationState
|
|
693
686
|
} = this;
|
|
694
687
|
// Only consider validation errors for which we actually have a field rendered
|
|
695
|
-
return
|
|
688
|
+
return validationState?.isResolved ? Object.keys(validationState.value).some(name => this.fields.has(name)) : false;
|
|
696
689
|
}
|
|
697
690
|
/**
|
|
698
691
|
* Call the passed validation callbacks, defined both on the whole form as well as on field level, and return the merged result for all fields.
|
|
699
692
|
*/
|
|
700
693
|
async validate() {
|
|
701
|
-
const
|
|
702
|
-
const
|
|
703
|
-
const
|
|
704
|
-
for (const [
|
|
705
|
-
const
|
|
706
|
-
if (
|
|
707
|
-
|
|
708
|
-
[
|
|
694
|
+
const nativeValidation = this.args.ignoreNativeValidation === true ? {} : this.validateNative();
|
|
695
|
+
const customFormValidation = await this.args.validate?.(this.effectiveData, [...this.fields.keys()]);
|
|
696
|
+
const customFieldValidations = [];
|
|
697
|
+
for (const [name, field] of this.fields) {
|
|
698
|
+
const fieldValidationResult = await field.validate?.(this.effectiveData[name], name, this.effectiveData);
|
|
699
|
+
if (fieldValidationResult) {
|
|
700
|
+
customFieldValidations.push({
|
|
701
|
+
[name]: fieldValidationResult
|
|
709
702
|
});
|
|
710
703
|
}
|
|
711
704
|
}
|
|
712
|
-
return mergeErrorRecord(
|
|
705
|
+
return mergeErrorRecord(nativeValidation, customFormValidation, ...customFieldValidations);
|
|
713
706
|
}
|
|
714
707
|
validateWithState = async () => {
|
|
715
|
-
const
|
|
716
|
-
this.validationState = new TrackedAsyncData(
|
|
717
|
-
return
|
|
708
|
+
const promise = this.validate();
|
|
709
|
+
this.validationState = new TrackedAsyncData(promise);
|
|
710
|
+
return promise;
|
|
718
711
|
};
|
|
719
712
|
validateNative() {
|
|
720
|
-
const
|
|
721
|
-
assert('Form element expected to be present. If you see this, please report it as a bug to ember-headless-form!',
|
|
722
|
-
if (
|
|
713
|
+
const form = this.formElement;
|
|
714
|
+
assert('Form element expected to be present. If you see this, please report it as a bug to ember-headless-form!', form);
|
|
715
|
+
if (form.checkValidity()) {
|
|
723
716
|
return;
|
|
724
717
|
}
|
|
725
|
-
const
|
|
726
|
-
for (const
|
|
718
|
+
const errors = {};
|
|
719
|
+
for (const el of form.elements) {
|
|
727
720
|
// This is just to make TS happy, as we need to access properties on el that only form elements have, but elements in `form.elements` are just typed as plain `Element`. Should never occur in reality.
|
|
728
|
-
assert('Unexpected form element. If you see this, please report it as a bug to ember-headless-form!',
|
|
729
|
-
if (
|
|
721
|
+
assert('Unexpected form element. If you see this, please report it as a bug to ember-headless-form!', el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement || el instanceof HTMLButtonElement || el instanceof HTMLFieldSetElement || el instanceof HTMLObjectElement || el instanceof HTMLOutputElement);
|
|
722
|
+
if (el.validity.valid) {
|
|
730
723
|
continue;
|
|
731
724
|
}
|
|
732
|
-
const
|
|
733
|
-
if (this.fields.has(
|
|
734
|
-
|
|
725
|
+
const name = el.name;
|
|
726
|
+
if (this.fields.has(name)) {
|
|
727
|
+
errors[name] = [{
|
|
735
728
|
type: 'native',
|
|
736
|
-
value: this.effectiveData[
|
|
737
|
-
message:
|
|
729
|
+
value: this.effectiveData[name],
|
|
730
|
+
message: el.validationMessage
|
|
738
731
|
}];
|
|
739
732
|
} else {
|
|
740
|
-
warn(`An invalid form element with name "${
|
|
733
|
+
warn(`An invalid form element with name "${name}" was detected, but this name is not used as a form field. It will be ignored for validation. Make sure to apply the correct name to custom form elements that participate in form validation!`, {
|
|
741
734
|
id: 'headless-form.invalid-control-for-unknown-field'
|
|
742
735
|
});
|
|
743
736
|
}
|
|
744
737
|
}
|
|
745
|
-
return
|
|
738
|
+
return errors;
|
|
746
739
|
}
|
|
747
740
|
/**
|
|
748
741
|
* Return a mapping of field to validation errors, for all fields that are invalid *and* for which validation errors should be visible.
|
|
@@ -753,44 +746,43 @@ class Form extends Component {
|
|
|
753
746
|
if (!this.validationState?.isResolved) {
|
|
754
747
|
return undefined;
|
|
755
748
|
}
|
|
756
|
-
const
|
|
757
|
-
for (const [
|
|
758
|
-
if (this.showErrorsFor(
|
|
759
|
-
|
|
749
|
+
const visibleErrors = {};
|
|
750
|
+
for (const [field, errors] of Object.entries(this.validationState.value)) {
|
|
751
|
+
if (this.showErrorsFor(field)) {
|
|
752
|
+
visibleErrors[field] = errors;
|
|
760
753
|
}
|
|
761
754
|
}
|
|
762
|
-
return
|
|
755
|
+
return visibleErrors;
|
|
763
756
|
}
|
|
764
757
|
/**
|
|
765
758
|
* Given a field name, return if eventual errors for the field should be visible. See `visibleErrors` for further details.
|
|
766
759
|
*/
|
|
767
|
-
showErrorsFor =
|
|
768
|
-
return this.showAllValidations || (this.fields.get(
|
|
760
|
+
showErrorsFor = field => {
|
|
761
|
+
return this.showAllValidations || (this.fields.get(field)?.validationEnabled ?? false);
|
|
769
762
|
};
|
|
770
763
|
/**
|
|
771
764
|
* Handle the `@validateOn` event for a certain field, e.g. "blur".
|
|
772
765
|
* Associating the event with a field is done by looking at the event target's `name` attribute, which must match one of the `<form.field @name="...">` invocations by the user's template.
|
|
773
766
|
* Validation will be triggered, and the particular field will be marked to show eventual validation errors.
|
|
774
767
|
*/
|
|
775
|
-
handleFieldValidation = async
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
name1 = e1;
|
|
768
|
+
handleFieldValidation = async e => {
|
|
769
|
+
let name;
|
|
770
|
+
if (typeof e === 'string') {
|
|
771
|
+
name = e;
|
|
780
772
|
} else {
|
|
781
773
|
const {
|
|
782
|
-
target
|
|
783
|
-
} =
|
|
784
|
-
|
|
774
|
+
target
|
|
775
|
+
} = e;
|
|
776
|
+
name = target.name;
|
|
785
777
|
}
|
|
786
|
-
if (
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
778
|
+
if (name) {
|
|
779
|
+
const field = this.fields.get(name);
|
|
780
|
+
if (field) {
|
|
789
781
|
await this.validateWithState();
|
|
790
|
-
|
|
782
|
+
field.validationEnabled = true;
|
|
791
783
|
}
|
|
792
|
-
} else if (
|
|
793
|
-
warn(`An event of type "${
|
|
784
|
+
} else if (e instanceof Event) {
|
|
785
|
+
warn(`An event of type "${e.type}" was received by headless-form, which is supposed to trigger validations for a certain field. But the name of that field could not be determined. Make sure that your control element has a \`name\` attribute matching the field, or use the yielded \`{{field.captureEvents}}\` to capture the events.`, {
|
|
794
786
|
id: 'headless-form.validation-event-for-unknown-field'
|
|
795
787
|
});
|
|
796
788
|
}
|
|
@@ -802,40 +794,40 @@ class Form extends Component {
|
|
|
802
794
|
*
|
|
803
795
|
* The use case here is to allow this to happen more frequently than the initial validation, e.g. `@validateOn="blur" @revalidateOn="change"`.
|
|
804
796
|
*/
|
|
805
|
-
handleFieldRevalidation = async
|
|
797
|
+
handleFieldRevalidation = async e => {
|
|
806
798
|
const {
|
|
807
|
-
target
|
|
808
|
-
} =
|
|
799
|
+
target
|
|
800
|
+
} = e;
|
|
809
801
|
const {
|
|
810
|
-
name
|
|
811
|
-
} =
|
|
812
|
-
if (
|
|
813
|
-
if (this.showErrorsFor(
|
|
802
|
+
name
|
|
803
|
+
} = target;
|
|
804
|
+
if (name) {
|
|
805
|
+
if (this.showErrorsFor(name)) {
|
|
814
806
|
await this.validateWithState();
|
|
815
807
|
}
|
|
816
808
|
} else {
|
|
817
|
-
warn(`An event of type "${
|
|
809
|
+
warn(`An event of type "${e.type}" was received by headless-form, which is supposed to trigger validations for a certain field. But the name of that field could not be determined. Make sure that your control element has a \`name\` attribute matching the field, or use the yielded \`{{field.captureEvents}}\` to capture the events.`, {
|
|
818
810
|
id: 'headless-form.validation-event-for-unknown-field'
|
|
819
811
|
});
|
|
820
812
|
}
|
|
821
813
|
};
|
|
822
|
-
attachValidation = modifier((
|
|
823
|
-
if (
|
|
824
|
-
|
|
825
|
-
return () =>
|
|
814
|
+
attachValidation = modifier((el, [eventName, handler]) => {
|
|
815
|
+
if (eventName) {
|
|
816
|
+
el.addEventListener(eventName, handler);
|
|
817
|
+
return () => el.removeEventListener(eventName, handler);
|
|
826
818
|
}
|
|
827
|
-
return
|
|
819
|
+
return;
|
|
828
820
|
});
|
|
829
821
|
static {
|
|
830
|
-
setComponentTemplate(precompileTemplate("\n <form novalidate class={{styles.form}} data-test-form ...attributes {{this.registerForm}} {{on \"submit\" this.submit}} {{on \"reset\" this.reset}} {{this.attachValidation this.fieldValidationEvent this.handleFieldValidation}} {{this.attachValidation this.fieldRevalidationEvent this.handleFieldRevalidation}}>\n {{#let (component this.Field data=this.effectiveData set=this.set errors=this.visibleErrors registerField=this.registerField unregisterField=this.unregisterField triggerValidationFor=this.handleFieldValidation fieldValidationEvent=this.fieldValidationEvent fieldRevalidationEvent=this.fieldRevalidationEvent
|
|
822
|
+
setComponentTemplate(precompileTemplate("\n <form novalidate class={{styles.form}} data-test-form ...attributes {{this.registerForm}} {{on \"submit\" this.submit}} {{on \"reset\" this.reset}} {{this.attachValidation this.fieldValidationEvent this.handleFieldValidation}} {{this.attachValidation this.fieldRevalidationEvent this.handleFieldRevalidation}}>\n {{#let (component this.Field data=this.effectiveData set=this.set errors=this.visibleErrors showErrorsFor=this.showErrorsFor registerField=this.registerField unregisterField=this.unregisterField triggerValidationFor=this.handleFieldValidation fieldValidationEvent=this.fieldValidationEvent fieldRevalidationEvent=this.fieldRevalidationEvent) as |WiredField|}}\n {{yield (hash Submit=Submit Reset=Reset Field=WiredField Checkbox=(component this.CheckboxField Field=WiredField) Currency=(component this.CurrencyField Field=WiredField) Date=(component this.DateField Field=WiredField) Email=(component this.EmailField Field=WiredField) List=(component this.ListField Field=WiredField) MultipleChoice=(component this.MultipleChoiceField Field=WiredField) Number=(component this.NumberField Field=WiredField) Range=(component this.RangeField Field=WiredField) Password=(component this.PasswordField Field=WiredField) Phone=(component this.PhoneField Field=WiredField) Select=(component this.SelectField Field=WiredField) SingularChoice=(component this.SingularChoiceField Field=WiredField) Text=(component this.TextField Field=WiredField) TextArea=(component this.TextAreaField Field=WiredField) validationState=this.validationState submissionState=this.submissionState invalid=this.validationErrorsExist rawErrors=this.visibleErrors submit=this.submit reset=this.reset)}}\n {{/let}}\n </form>\n ", {
|
|
823
|
+
strictMode: true,
|
|
831
824
|
scope: () => ({
|
|
832
825
|
styles,
|
|
833
826
|
on,
|
|
834
827
|
hash,
|
|
835
828
|
Submit,
|
|
836
829
|
Reset
|
|
837
|
-
})
|
|
838
|
-
strictMode: true
|
|
830
|
+
})
|
|
839
831
|
}), this);
|
|
840
832
|
}
|
|
841
833
|
}
|