@ember-eui/validated-form 7.1.4 → 8.0.0-beta.12
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/addon-main.js +5 -0
- package/declarations/components/validated-form/field-base/index.d.ts +37 -0
- package/declarations/components/validated-form/field-base/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-base.d.ts +56 -0
- package/declarations/components/validated-form/field-base.d.ts.map +1 -0
- package/declarations/components/validated-form/field-checkbox-group/index.d.ts +8 -0
- package/declarations/components/validated-form/field-checkbox-group/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-checkbox-group.d.ts +30 -0
- package/declarations/components/validated-form/field-checkbox-group.d.ts.map +1 -0
- package/declarations/components/validated-form/field-combo-box/index.d.ts +5 -0
- package/declarations/components/validated-form/field-combo-box/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-combo-box.d.ts +27 -0
- package/declarations/components/validated-form/field-combo-box.d.ts.map +1 -0
- package/declarations/components/validated-form/field-dual-range-slider/index.d.ts +5 -0
- package/declarations/components/validated-form/field-dual-range-slider/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-dual-range-slider.d.ts +32 -0
- package/declarations/components/validated-form/field-dual-range-slider.d.ts.map +1 -0
- package/{addon/components/validated-form/field-markdown-editor/index.js → declarations/components/validated-form/field-markdown-editor/index.d.ts} +3 -8
- package/declarations/components/validated-form/field-markdown-editor/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-markdown-editor.d.ts +25 -0
- package/declarations/components/validated-form/field-markdown-editor.d.ts.map +1 -0
- package/{addon/components/validated-form/field-number/index.js → declarations/components/validated-form/field-number/index.d.ts} +3 -2
- package/declarations/components/validated-form/field-number/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-number.d.ts +24 -0
- package/declarations/components/validated-form/field-number.d.ts.map +1 -0
- package/{addon/components/validated-form/field-password/index.js → declarations/components/validated-form/field-password/index.d.ts} +3 -2
- package/declarations/components/validated-form/field-password/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-password.d.ts +24 -0
- package/declarations/components/validated-form/field-password.d.ts.map +1 -0
- package/declarations/components/validated-form/field-radio-group/index.d.ts +8 -0
- package/declarations/components/validated-form/field-radio-group/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-radio-group.d.ts +29 -0
- package/declarations/components/validated-form/field-radio-group.d.ts.map +1 -0
- package/{addon/components/validated-form/field-range-slider/index.js → declarations/components/validated-form/field-range-slider/index.d.ts} +3 -2
- package/declarations/components/validated-form/field-range-slider/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-range-slider.d.ts +28 -0
- package/declarations/components/validated-form/field-range-slider.d.ts.map +1 -0
- package/{addon/components/validated-form/field-select/index.js → declarations/components/validated-form/field-select/index.d.ts} +3 -2
- package/declarations/components/validated-form/field-select/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-select.d.ts +23 -0
- package/declarations/components/validated-form/field-select.d.ts.map +1 -0
- package/declarations/components/validated-form/field-switch/index.d.ts +5 -0
- package/declarations/components/validated-form/field-switch/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-switch.d.ts +24 -0
- package/declarations/components/validated-form/field-switch.d.ts.map +1 -0
- package/{addon/components/validated-form/field-text/index.js → declarations/components/validated-form/field-text/index.d.ts} +3 -2
- package/declarations/components/validated-form/field-text/index.d.ts.map +1 -0
- package/{addon/components/validated-form/field-text-area/index.js → declarations/components/validated-form/field-text-area/index.d.ts} +3 -2
- package/declarations/components/validated-form/field-text-area/index.d.ts.map +1 -0
- package/declarations/components/validated-form/field-text-area.d.ts +29 -0
- package/declarations/components/validated-form/field-text-area.d.ts.map +1 -0
- package/declarations/components/validated-form/field-text.d.ts +22 -0
- package/declarations/components/validated-form/field-text.d.ts.map +1 -0
- package/declarations/components/validated-form/index.d.ts +30 -0
- package/declarations/components/validated-form/index.d.ts.map +1 -0
- package/declarations/components/validated-form.d.ts +91 -0
- package/declarations/components/validated-form.d.ts.map +1 -0
- package/declarations/utils/build-validation-messages.d.ts +13 -0
- package/declarations/utils/build-validation-messages.d.ts.map +1 -0
- package/declarations/utils/get-messages.d.ts +11 -0
- package/declarations/utils/get-messages.d.ts.map +1 -0
- package/declarations/utils/validation-errors.d.ts +2 -0
- package/declarations/utils/validation-errors.d.ts.map +1 -0
- package/declarations/utils/with-defaults.d.ts +10 -0
- package/declarations/utils/with-defaults.d.ts.map +1 -0
- package/declarations/validators/messages.d.ts +4 -0
- package/declarations/validators/messages.d.ts.map +1 -0
- package/dist/_app_/components/validated-form/field-base.js +1 -0
- package/dist/_app_/components/validated-form/field-checkbox-group.js +1 -0
- package/dist/_app_/components/validated-form/field-combo-box.js +1 -0
- package/dist/_app_/components/validated-form/field-dual-range-slider.js +1 -0
- package/dist/_app_/components/validated-form/field-markdown-editor.js +1 -0
- package/dist/_app_/components/validated-form/field-number.js +1 -0
- package/dist/_app_/components/validated-form/field-password.js +1 -0
- package/dist/_app_/components/validated-form/field-radio-group.js +1 -0
- package/dist/_app_/components/validated-form/field-range-slider.js +1 -0
- package/dist/_app_/components/validated-form/field-select.js +1 -0
- package/dist/_app_/components/validated-form/field-switch.js +1 -0
- package/dist/_app_/components/validated-form/field-text-area.js +1 -0
- package/dist/_app_/components/validated-form/field-text.js +1 -0
- package/dist/_app_/components/validated-form.js +1 -0
- package/dist/_app_/utils/build-validation-messages.js +1 -0
- package/dist/_app_/utils/get-messages.js +1 -0
- package/dist/_app_/utils/validation-errors.js +1 -0
- package/dist/_app_/utils/with-defaults.js +1 -0
- package/dist/_app_/validators/messages.js +1 -0
- package/dist/components/validated-form/field-base.js +7 -0
- package/dist/components/validated-form/field-base.js.map +1 -0
- package/dist/components/validated-form/field-checkbox-group.js +104 -0
- package/dist/components/validated-form/field-checkbox-group.js.map +1 -0
- package/dist/components/validated-form/field-combo-box.js +106 -0
- package/dist/components/validated-form/field-combo-box.js.map +1 -0
- package/dist/components/validated-form/field-dual-range-slider.js +112 -0
- package/dist/components/validated-form/field-dual-range-slider.js.map +1 -0
- package/dist/components/validated-form/field-markdown-editor.js +102 -0
- package/dist/components/validated-form/field-markdown-editor.js.map +1 -0
- package/dist/components/validated-form/field-number.js +94 -0
- package/dist/components/validated-form/field-number.js.map +1 -0
- package/dist/components/validated-form/field-password.js +87 -0
- package/dist/components/validated-form/field-password.js.map +1 -0
- package/dist/components/validated-form/field-radio-group.js +102 -0
- package/dist/components/validated-form/field-radio-group.js.map +1 -0
- package/dist/components/validated-form/field-range-slider.js +119 -0
- package/dist/components/validated-form/field-range-slider.js.map +1 -0
- package/dist/components/validated-form/field-select.js +88 -0
- package/dist/components/validated-form/field-select.js.map +1 -0
- package/dist/components/validated-form/field-switch.js +87 -0
- package/dist/components/validated-form/field-switch.js.map +1 -0
- package/dist/components/validated-form/field-text-area.js +80 -0
- package/dist/components/validated-form/field-text-area.js.map +1 -0
- package/dist/components/validated-form/field-text.js +90 -0
- package/dist/components/validated-form/field-text.js.map +1 -0
- package/dist/components/validated-form.js +303 -0
- package/dist/components/validated-form.js.map +1 -0
- package/dist/field-base-t4F7Xj_I.js +185 -0
- package/dist/field-base-t4F7Xj_I.js.map +1 -0
- package/{addon → dist}/utils/build-validation-messages.js +13 -36
- package/dist/utils/build-validation-messages.js.map +1 -0
- package/{addon → dist}/utils/get-messages.js +6 -7
- package/dist/utils/get-messages.js.map +1 -0
- package/dist/utils/validation-errors.js +18 -0
- package/dist/utils/validation-errors.js.map +1 -0
- package/{addon → dist}/utils/with-defaults.js +5 -2
- package/dist/utils/with-defaults.js.map +1 -0
- package/dist/validators/messages.js +7 -0
- package/dist/validators/messages.js.map +1 -0
- package/package.json +116 -76
- package/addon/components/validated-form/field-base/index.js +0 -144
- package/addon/components/validated-form/field-checkbox-group/index.hbs +0 -47
- package/addon/components/validated-form/field-checkbox-group/index.js +0 -42
- package/addon/components/validated-form/field-combo-box/index.hbs +0 -65
- package/addon/components/validated-form/field-combo-box/index.js +0 -12
- package/addon/components/validated-form/field-dual-range-slider/index.hbs +0 -80
- package/addon/components/validated-form/field-dual-range-slider/index.js +0 -12
- package/addon/components/validated-form/field-markdown-editor/index.hbs +0 -61
- package/addon/components/validated-form/field-number/index.hbs +0 -63
- package/addon/components/validated-form/field-password/index.hbs +0 -56
- package/addon/components/validated-form/field-radio-group/index.hbs +0 -45
- package/addon/components/validated-form/field-radio-group/index.js +0 -39
- package/addon/components/validated-form/field-range-slider/index.hbs +0 -93
- package/addon/components/validated-form/field-select/index.hbs +0 -57
- package/addon/components/validated-form/field-switch/index.hbs +0 -48
- package/addon/components/validated-form/field-switch/index.js +0 -12
- package/addon/components/validated-form/field-text/index.hbs +0 -59
- package/addon/components/validated-form/field-text-area/index.hbs +0 -54
- package/addon/components/validated-form/index.hbs +0 -158
- package/addon/components/validated-form/index.js +0 -132
- package/addon/utils/validation-errors.js +0 -13
- package/addon/validators/messages.js +0 -4
- package/app/components/validated-form/field-base/index.js +0 -1
- package/app/components/validated-form/field-checkbox-group/index.js +0 -1
- package/app/components/validated-form/field-combo-box/index.js +0 -1
- package/app/components/validated-form/field-dual-range-slider/index.js +0 -1
- package/app/components/validated-form/field-markdown-editor/index.js +0 -1
- package/app/components/validated-form/field-number/index.js +0 -1
- package/app/components/validated-form/field-password/index.js +0 -1
- package/app/components/validated-form/field-radio-group/index.js +0 -1
- package/app/components/validated-form/field-range-slider/index.js +0 -1
- package/app/components/validated-form/field-select/index.js +0 -1
- package/app/components/validated-form/field-switch/index.js +0 -1
- package/app/components/validated-form/field-text/index.js +0 -1
- package/app/components/validated-form/field-text-area/index.js +0 -1
- package/app/components/validated-form/index.js +0 -1
- package/app/utils/build-validation-messages.js +0 -1
- package/app/utils/get-messages.js +0 -1
- package/app/utils/validation-errors.js +0 -1
- package/app/validators/messages.js +0 -1
- package/config/environment.js +0 -5
- package/docs/validated-form-demo/demo1.md +0 -162
- package/docs/validated-form.md +0 -1
- package/index.js +0 -5
- package/tsconfig.json +0 -27
- package/types/dummy/index.d.ts +0 -1
- package/types/global.d.ts +0 -22
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
{{#let (arg-or-default @id (unique-id)) as |formId|}}
|
|
2
|
-
<EuiForm
|
|
3
|
-
@tagName={{arg-or-default @tagName "form"}}
|
|
4
|
-
...attributes
|
|
5
|
-
id={{formId}}
|
|
6
|
-
@isInvalid={{@isInvalid}}
|
|
7
|
-
@invalidCallout={{@invalidCallout}}
|
|
8
|
-
@error={{@error}}
|
|
9
|
-
@errorTitle={{@errorTitle}}
|
|
10
|
-
{{on "submit" this.handleSubmit}}
|
|
11
|
-
{{on "reset" this.handleReset}}
|
|
12
|
-
{{did-insert this.setNewValidity}}
|
|
13
|
-
>
|
|
14
|
-
{{yield
|
|
15
|
-
(hash
|
|
16
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
17
|
-
onValidityChange=this.onChildValidityChange
|
|
18
|
-
register=this.register
|
|
19
|
-
unregister=this.unregister
|
|
20
|
-
isValid=this.isValid
|
|
21
|
-
isInvalid=this.isInvalid
|
|
22
|
-
isTouched=this.isTouched
|
|
23
|
-
isInvalidAndTouched=this.isInvalidAndTouched
|
|
24
|
-
formId=formId
|
|
25
|
-
FieldNumber=(component
|
|
26
|
-
"validated-form/field-number"
|
|
27
|
-
register=this.register
|
|
28
|
-
unregister=this.unregister
|
|
29
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
30
|
-
onValidityChange=this.onChildValidityChange
|
|
31
|
-
fullWidth=@fullWidth
|
|
32
|
-
formId=formId
|
|
33
|
-
disabled=@isDisabled
|
|
34
|
-
)
|
|
35
|
-
FieldText=(component
|
|
36
|
-
"validated-form/field-text"
|
|
37
|
-
register=this.register
|
|
38
|
-
unregister=this.unregister
|
|
39
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
40
|
-
onValidityChange=this.onChildValidityChange
|
|
41
|
-
fullWidth=@fullWidth
|
|
42
|
-
formId=formId
|
|
43
|
-
disabled=@isDisabled
|
|
44
|
-
)
|
|
45
|
-
FieldPassword=(component
|
|
46
|
-
"validated-form/field-password"
|
|
47
|
-
register=this.register
|
|
48
|
-
unregister=this.unregister
|
|
49
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
50
|
-
onValidityChange=this.onChildValidityChange
|
|
51
|
-
fullWidth=@fullWidth
|
|
52
|
-
formId=formId
|
|
53
|
-
disabled=@isDisabled
|
|
54
|
-
)
|
|
55
|
-
FieldTextArea=(component
|
|
56
|
-
"validated-form/field-text-area"
|
|
57
|
-
register=this.register
|
|
58
|
-
unregister=this.unregister
|
|
59
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
60
|
-
onValidityChange=this.onChildValidityChange
|
|
61
|
-
fullWidth=@fullWidth
|
|
62
|
-
formId=formId
|
|
63
|
-
disabled=@isDisabled
|
|
64
|
-
)
|
|
65
|
-
FieldSelect=(component
|
|
66
|
-
"validated-form/field-select"
|
|
67
|
-
register=this.register
|
|
68
|
-
unregister=this.unregister
|
|
69
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
70
|
-
onValidityChange=this.onChildValidityChange
|
|
71
|
-
fullWidth=@fullWidth
|
|
72
|
-
formId=formId
|
|
73
|
-
disabled=@isDisabled
|
|
74
|
-
)
|
|
75
|
-
FieldComboBox=(component
|
|
76
|
-
"validated-form/field-combo-box"
|
|
77
|
-
register=this.register
|
|
78
|
-
unregister=this.unregister
|
|
79
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
80
|
-
onValidityChange=this.onChildValidityChange
|
|
81
|
-
fullWidth=@fullWidth
|
|
82
|
-
formId=formId
|
|
83
|
-
isDisabled=@isDisabled
|
|
84
|
-
)
|
|
85
|
-
FieldCheckboxGroup=(component
|
|
86
|
-
"validated-form/field-checkbox-group"
|
|
87
|
-
register=this.register
|
|
88
|
-
unregister=this.unregister
|
|
89
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
90
|
-
onValidityChange=this.onChildValidityChange
|
|
91
|
-
fullWidth=@fullWidth
|
|
92
|
-
formId=formId
|
|
93
|
-
disabled=@isDisabled
|
|
94
|
-
)
|
|
95
|
-
FieldRadioGroup=(component
|
|
96
|
-
"validated-form/field-radio-group"
|
|
97
|
-
register=this.register
|
|
98
|
-
unregister=this.unregister
|
|
99
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
100
|
-
onValidityChange=this.onChildValidityChange
|
|
101
|
-
fullWidth=@fullWidth
|
|
102
|
-
formId=formId
|
|
103
|
-
disabled=@isDisabled
|
|
104
|
-
)
|
|
105
|
-
FieldRangeSlider=(component
|
|
106
|
-
"validated-form/field-range-slider"
|
|
107
|
-
register=this.register
|
|
108
|
-
unregister=this.unregister
|
|
109
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
110
|
-
onValidityChange=this.onChildValidityChange
|
|
111
|
-
fullWidth=@fullWidth
|
|
112
|
-
formId=formId
|
|
113
|
-
disabled=@isDisabled
|
|
114
|
-
)
|
|
115
|
-
FieldDualRangeSlider=(component
|
|
116
|
-
"validated-form/field-dual-range-slider"
|
|
117
|
-
register=this.register
|
|
118
|
-
unregister=this.unregister
|
|
119
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
120
|
-
onValidityChange=this.onChildValidityChange
|
|
121
|
-
fullWidth=@fullWidth
|
|
122
|
-
formId=formId
|
|
123
|
-
disabled=@isDisabled
|
|
124
|
-
)
|
|
125
|
-
FieldSwitch=(component
|
|
126
|
-
"validated-form/field-switch"
|
|
127
|
-
register=this.register
|
|
128
|
-
unregister=this.unregister
|
|
129
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
130
|
-
onValidityChange=this.onChildValidityChange
|
|
131
|
-
fullWidth=@fullWidth
|
|
132
|
-
formId=formId
|
|
133
|
-
disabled=@isDisabled
|
|
134
|
-
)
|
|
135
|
-
FieldMarkdownEditor=(component
|
|
136
|
-
"validated-form/field-markdown-editor"
|
|
137
|
-
register=this.register
|
|
138
|
-
unregister=this.unregister
|
|
139
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
140
|
-
onValidityChange=this.onChildValidityChange
|
|
141
|
-
fullWidth=@fullWidth
|
|
142
|
-
formId=formId
|
|
143
|
-
disabled=@isDisabled
|
|
144
|
-
)
|
|
145
|
-
FieldNestedForm=(component
|
|
146
|
-
"validated-form"
|
|
147
|
-
register=this.register
|
|
148
|
-
unregister=this.unregister
|
|
149
|
-
formHasBeenValidated=this.formHasBeenValidated
|
|
150
|
-
onValidityChange=this.onChildValidityChange
|
|
151
|
-
fullWidth=@fullWidth
|
|
152
|
-
formId=formId
|
|
153
|
-
disabled=@isDisabled
|
|
154
|
-
)
|
|
155
|
-
)
|
|
156
|
-
}}
|
|
157
|
-
</EuiForm>
|
|
158
|
-
{{/let}}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import Component from '@glimmer/component';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
import { tracked } from '@glimmer/tracking';
|
|
4
|
-
import { A } from '@ember/array';
|
|
5
|
-
import { schedule, next } from '@ember/runloop';
|
|
6
|
-
|
|
7
|
-
export default class ValidatedForm extends Component {
|
|
8
|
-
@tracked childComponents = A([]);
|
|
9
|
-
//cache to only notify if changed
|
|
10
|
-
lastIsValid;
|
|
11
|
-
lastIsTouched;
|
|
12
|
-
|
|
13
|
-
@tracked isInvalid = false;
|
|
14
|
-
@tracked isTouched = false;
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this.args.register?.(this);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
willDestroy() {
|
|
22
|
-
super.willDestroy(...arguments);
|
|
23
|
-
this.args.unregister?.(this);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get isValid() {
|
|
27
|
-
return !this.isInvalid;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get isInvalidAndTouched() {
|
|
31
|
-
return this.isInvalid && this.isTouched;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
addChild(child) {
|
|
35
|
-
this.childComponents.pushObject(child);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
removeChild(child) {
|
|
39
|
-
this.childComponents.removeObject(child);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@action
|
|
43
|
-
async handleSubmit(e) {
|
|
44
|
-
e.preventDefault();
|
|
45
|
-
if (this.isInvalid) {
|
|
46
|
-
this.childComponents.setEach('isTouched', true);
|
|
47
|
-
this.args.onInvalid?.();
|
|
48
|
-
} else {
|
|
49
|
-
this.childComponents.setEach('isTouched', false);
|
|
50
|
-
try {
|
|
51
|
-
await this.args.onSubmit?.();
|
|
52
|
-
} catch (e) {
|
|
53
|
-
this.childComponents.setEach('isTouched', true);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@action
|
|
59
|
-
handleReset(e) {
|
|
60
|
-
e.preventDefault();
|
|
61
|
-
this.args.onReset?.(e);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@action
|
|
65
|
-
register(child) {
|
|
66
|
-
if (!this.isDestroyed) {
|
|
67
|
-
schedule('afterRender', this, this.addChild, child);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@action
|
|
72
|
-
unregister(child) {
|
|
73
|
-
if (!this.isDestroyed) {
|
|
74
|
-
schedule('afterRender', this, this.removeChild, child);
|
|
75
|
-
// When adding a child the validation gets calculated on a `did-insert` modifier
|
|
76
|
-
// for removal there's no modifier so it gets called here
|
|
77
|
-
schedule('afterRender', this, this.triggerValidityChange);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@action
|
|
82
|
-
updateValidity() {
|
|
83
|
-
this.triggerValidityChange();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getIsValid() {
|
|
87
|
-
return this.childComponents.isEvery('isValid');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getIsTouched() {
|
|
91
|
-
return this.childComponents.isAny('isTouched');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
triggerValidityChange() {
|
|
95
|
-
const lastIsValid = this.isValid;
|
|
96
|
-
const lastIsTouched = this.isTouched;
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
lastIsValid !== this.getIsValid() ||
|
|
100
|
-
lastIsTouched !== this.getIsTouched()
|
|
101
|
-
) {
|
|
102
|
-
this.setNewValidity();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@action
|
|
107
|
-
setNewValidity() {
|
|
108
|
-
next(() => {
|
|
109
|
-
this.isInvalid = !this.getIsValid();
|
|
110
|
-
this.isTouched = this.getIsTouched();
|
|
111
|
-
if (!this.isDestroying) {
|
|
112
|
-
this.args.onValidityChange?.(
|
|
113
|
-
this.isValid,
|
|
114
|
-
this.isTouched,
|
|
115
|
-
this.isInvalidAndTouched
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@action
|
|
122
|
-
onChildValidityChange({ child, isValid, isTouched, isInvalidAndTouched }) {
|
|
123
|
-
if (!this.isDestroying) {
|
|
124
|
-
this.updateValidity({
|
|
125
|
-
child,
|
|
126
|
-
isValid,
|
|
127
|
-
isTouched,
|
|
128
|
-
isInvalidAndTouched
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { assign } from '@ember/polyfills';
|
|
2
|
-
|
|
3
|
-
export default function buildMessage(messages, key, result = {}) {
|
|
4
|
-
let description = messages.getDescriptionFor(key);
|
|
5
|
-
|
|
6
|
-
if (result?.context?.message) {
|
|
7
|
-
return result.context.message;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
let { type, context = {} } = result;
|
|
11
|
-
|
|
12
|
-
return messages.getMessageFor(type, assign({ description }, context));
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-base';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-checkbox-group';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-combo-box';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-dual-range-slider';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-markdown-editor';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-number';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-password';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-radio-group';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-range-slider';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-select';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-switch';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-text';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form/field-text-area';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/components/validated-form';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/utils/build-validation-messages';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/utils/get-messages';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/utils/validation-errors';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '@ember-eui/validated-form/validators/messages';
|
package/config/environment.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
# Validated form
|
|
2
|
-
|
|
3
|
-
<EuiText>
|
|
4
|
-
<p>Inspired on <strong>ember-paper</strong>'s <EuiCode>{{t "validated_form.ember_paper"}}</EuiCode></p>
|
|
5
|
-
|
|
6
|
-
<p>The idea is simple, <strong>ValidatedForm</strong> yields most basic <strong>@ember-eui/core</strong> components with some wiring to keep the form state on sync.</p>
|
|
7
|
-
|
|
8
|
-
<p>It uses <EuiLink @target="_blank" @href="https://github.com/offirgolan/ember-validators">ember-validators</EuiLink> by default to describe the validations. To provide the validations ergonomically you'd just pass a hash where each key is a valid
|
|
9
|
-
ember-valitador validator, <EuiCode>length</EuiCode>, <EuiCode>presence</EuiCode>, <EuiCode>number</EuiCode>, the values and the <EuiCode>config</EuiCode> expected by those.</p>
|
|
10
|
-
|
|
11
|
-
<p><EuiCodeBlock @isCopyable={{true}}>ember install @ember-eui/validated-form</EuiCodeBlock></p>
|
|
12
|
-
|
|
13
|
-
</EuiText>
|
|
14
|
-
|
|
15
|
-
```hbs template
|
|
16
|
-
<ValidatedForm as |Form|>
|
|
17
|
-
<Form.FieldText
|
|
18
|
-
@value={{this.data.fieldText}}
|
|
19
|
-
@label='Email'
|
|
20
|
-
@onChange={{set this.data 'fieldText'}}
|
|
21
|
-
@validations={{hash
|
|
22
|
-
presence=(hash presence=true)
|
|
23
|
-
format=(hash type='email')
|
|
24
|
-
}}
|
|
25
|
-
/>
|
|
26
|
-
<Form.FieldMarkdownEditor
|
|
27
|
-
@value={{this.data.markdownText}}
|
|
28
|
-
@label='Markdown'
|
|
29
|
-
@onChange={{set this.data 'markdownText'}}
|
|
30
|
-
@validations={{hash presence=(hash presence=true)}}
|
|
31
|
-
@error={{array 'one error'}}
|
|
32
|
-
/>
|
|
33
|
-
<Form.FieldSelect
|
|
34
|
-
@onChange={{set this.data 'fieldSelect'}}
|
|
35
|
-
@value={{this.data.fieldSelect}}
|
|
36
|
-
@validations={{hash presence=(hash presence=true)}}
|
|
37
|
-
@options={{array
|
|
38
|
-
(hash value='mx' text='Mexico')
|
|
39
|
-
(hash value='pt' text='Portugal')
|
|
40
|
-
(hash value='us' text='United States')
|
|
41
|
-
}}
|
|
42
|
-
@label='Country'
|
|
43
|
-
/>
|
|
44
|
-
<Form.FieldComboBox
|
|
45
|
-
@onChange={{set this.data 'fieldComboBoxSingleSelection'}}
|
|
46
|
-
@singleSelection={{true}}
|
|
47
|
-
@selectedOptions={{this.data.fieldComboBoxSingleSelection}}
|
|
48
|
-
@validations={{hash presence=(hash presence=true)}}
|
|
49
|
-
@required={{true}}
|
|
50
|
-
@options={{array
|
|
51
|
-
(hash value='mx' text='Mexico')
|
|
52
|
-
(hash value='pt' text='Portugal')
|
|
53
|
-
(hash value='us' text='United States')
|
|
54
|
-
}}
|
|
55
|
-
@label='fieldComboBoxSingleSelection'
|
|
56
|
-
as |option|
|
|
57
|
-
>
|
|
58
|
-
{{option.text}}
|
|
59
|
-
</Form.FieldComboBox>
|
|
60
|
-
<Form.FieldComboBox
|
|
61
|
-
@onChange={{set this.data 'fieldComboBoxMultiple'}}
|
|
62
|
-
@selectedOptions={{this.data.fieldComboBoxMultiple}}
|
|
63
|
-
@validations={{hash presence=(hash presence=true) length=(hash min=2)}}
|
|
64
|
-
@hasNoInitialSelection={{true}}
|
|
65
|
-
@options={{array
|
|
66
|
-
(hash value='mx' text='Mexico')
|
|
67
|
-
(hash value='pt' text='Portugal')
|
|
68
|
-
(hash value='us' text='United States')
|
|
69
|
-
}}
|
|
70
|
-
@label='fieldComboBoxMultiple'
|
|
71
|
-
as |option|
|
|
72
|
-
>
|
|
73
|
-
{{option.text}}
|
|
74
|
-
</Form.FieldComboBox>
|
|
75
|
-
<Form.FieldRangeSlider
|
|
76
|
-
@onChange={{set this.data 'rangeSlider'}}
|
|
77
|
-
@value={{this.data.rangeSlider}}
|
|
78
|
-
@label='Range slider'
|
|
79
|
-
@showLabels={{true}}
|
|
80
|
-
@showValue={{true}}
|
|
81
|
-
@min={{0}}
|
|
82
|
-
@max={{300}}
|
|
83
|
-
@validations={{hash
|
|
84
|
-
number=(hash gte=0 lte=100 allowString=true)
|
|
85
|
-
presence=(hash presence=true)
|
|
86
|
-
}}
|
|
87
|
-
@required={{true}}
|
|
88
|
-
/>
|
|
89
|
-
<Form.FieldCheckboxGroup
|
|
90
|
-
@onChange={{set this.data 'fieldCheckbox'}}
|
|
91
|
-
@validations={{hash presence=(hash presence=true) length=(hash min=1)}}
|
|
92
|
-
@value={{this.data.fieldCheckbox}}
|
|
93
|
-
@options={{array
|
|
94
|
-
(hash id='checkbox-1' label='Checkbox 1')
|
|
95
|
-
(hash id='checkbox-2' label='Checkbox 2')
|
|
96
|
-
(hash id='checkbox-3' label='Checkbox 3')
|
|
97
|
-
}}
|
|
98
|
-
@label='Checkbox Group'
|
|
99
|
-
/>
|
|
100
|
-
<Form.FieldRadioGroup
|
|
101
|
-
@onChange={{set this.data 'fieldRadioGroup'}}
|
|
102
|
-
@validations={{hash presence=(hash presence=true)}}
|
|
103
|
-
@value={{this.data.fieldRadioGroup}}
|
|
104
|
-
@options={{array
|
|
105
|
-
(hash id='radio-1' label='Radio 1')
|
|
106
|
-
(hash id='radio-2' label='Radio 2')
|
|
107
|
-
(hash id='radio-3' label='Radio 3')
|
|
108
|
-
}}
|
|
109
|
-
@label='Radio Group'
|
|
110
|
-
/>
|
|
111
|
-
<Form.FieldNumber
|
|
112
|
-
@value={{this.data.fieldNumber}}
|
|
113
|
-
@onChange={{set this.data 'fieldNumber'}}
|
|
114
|
-
@validations={{hash number=(hash lt=10 allowString=true)}}
|
|
115
|
-
@label='Less than 10'
|
|
116
|
-
@errors={{this.data.errors}}
|
|
117
|
-
/>
|
|
118
|
-
<Form.FieldPassword
|
|
119
|
-
@value={{this.data.fieldPassword}}
|
|
120
|
-
@onChange={{set this.data 'fieldPassword'}}
|
|
121
|
-
@validations={{hash presence=(hash presence=true)}}
|
|
122
|
-
>
|
|
123
|
-
<:label>
|
|
124
|
-
Field password
|
|
125
|
-
</:label>
|
|
126
|
-
</Form.FieldPassword>
|
|
127
|
-
<Form.FieldTextArea
|
|
128
|
-
@value={{this.data.fieldTextArea}}
|
|
129
|
-
@onChange={{set this.data 'fieldTextArea'}}
|
|
130
|
-
@validations={{hash length=(hash min=10) presence=(hash presence=true)}}
|
|
131
|
-
@label='Field Text minlength 10'
|
|
132
|
-
/>
|
|
133
|
-
<Form.FieldSwitch
|
|
134
|
-
@validations={{hash presence=(hash presence=true)}}
|
|
135
|
-
@value={{this.data.fieldSwitch}}
|
|
136
|
-
@label='Field must be true'
|
|
137
|
-
@onChange={{set this.data 'fieldSwitch'}}
|
|
138
|
-
/>
|
|
139
|
-
<Form.FieldNestedForm as |NestedForm|>
|
|
140
|
-
<NestedForm.FieldText
|
|
141
|
-
@validations={{hash presence=(hash presence=true)}}
|
|
142
|
-
@label='Nested form field text'
|
|
143
|
-
@value={{this.data.nestedFormFieldText}}
|
|
144
|
-
@onChange={{set this.data 'nestedFormFieldText'}}
|
|
145
|
-
/>
|
|
146
|
-
</Form.FieldNestedForm>
|
|
147
|
-
<EuiButton @type='submit'>
|
|
148
|
-
Submit
|
|
149
|
-
</EuiButton>
|
|
150
|
-
</ValidatedForm>
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
```js component
|
|
154
|
-
import Component from '@glimmer/component';
|
|
155
|
-
import { action } from '@ember/object';
|
|
156
|
-
import { tracked } from '@glimmer/tracking';
|
|
157
|
-
import O from '@ember/object';
|
|
158
|
-
|
|
159
|
-
export default class DemoCardComponent extends Component {
|
|
160
|
-
@tracked data = O.create({});
|
|
161
|
-
}
|
|
162
|
-
```
|
package/docs/validated-form.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<!-- empty on purpose -->
|
package/index.js
DELETED
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": ".",
|
|
5
|
-
"paths": {
|
|
6
|
-
"dummy/tests/*": ["tests/*"],
|
|
7
|
-
"@glimmer/tracking": [
|
|
8
|
-
"../../node_modules/ember-cached-decorator-polyfill",
|
|
9
|
-
"../../node_modules/@glimmer/tracking/dist/types"
|
|
10
|
-
],
|
|
11
|
-
"dummy/*": ["tests/dummy/app/*", "app/*"],
|
|
12
|
-
"changeset-form": ["addon"],
|
|
13
|
-
"changeset-form/*": ["addon/*"],
|
|
14
|
-
"changeset-form/test-support": ["addon-test-support"],
|
|
15
|
-
"changeset-form/test-support/*": ["addon-test-support/*"],
|
|
16
|
-
"*": ["types/*"]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"include": [
|
|
20
|
-
"app/**/*",
|
|
21
|
-
"addon/**/*",
|
|
22
|
-
"tests/**/*",
|
|
23
|
-
"types/**/*",
|
|
24
|
-
"test-support/**/*",
|
|
25
|
-
"addon-test-support/**/*"
|
|
26
|
-
]
|
|
27
|
-
}
|
package/types/dummy/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/types/global.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Types for compiled templates
|
|
2
|
-
declare module '@ember-eui/validated-form/templates/*' {
|
|
3
|
-
import { TemplateFactory } from 'htmlbars-inline-precompile';
|
|
4
|
-
const tmpl: TemplateFactory;
|
|
5
|
-
export default tmpl;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface Validator {
|
|
9
|
-
param: string;
|
|
10
|
-
message: string;
|
|
11
|
-
validate: (value: any, ...params: any[]) => boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type ErrorMessages = Record<string, string>;
|
|
15
|
-
|
|
16
|
-
type ExtraError = { message: string } | string;
|
|
17
|
-
|
|
18
|
-
interface ValidateableControl {
|
|
19
|
-
customValidations?: Array<Validator>;
|
|
20
|
-
errorMessages?: ErrorMessages;
|
|
21
|
-
errors?: Array<ExtraError>;
|
|
22
|
-
}
|