dlg-ui 1.0.34 → 1.0.36
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.
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
<form>
|
|
3
3
|
{{yield (hash Field=(component "form/field" addValidator=this.addValidator didValidate=this.didValidate errors=this.errors validate=this.validate))}}
|
|
4
4
|
</form>
|
|
5
|
+
<div class="form-actions">
|
|
5
6
|
<ButtonPrimary @onClick={{this.submitForm}}>
|
|
6
7
|
{{this.submitButtonText}}
|
|
7
8
|
</ButtonPrimary>
|
|
9
|
+
{{#if @secondaryButtonText}}
|
|
10
|
+
<ButtonPrimary @onClick={{@secondaryAction}} style="margin-left: 1em;">
|
|
11
|
+
{{@secondaryButtonText}}
|
|
12
|
+
</ButtonPrimary>
|
|
13
|
+
{{/if}}
|
|
14
|
+
</div>
|
|
8
15
|
</div>
|
package/addon/components/form.js
CHANGED
|
@@ -18,14 +18,19 @@ export default class FormComponent extends Component {
|
|
|
18
18
|
this.validations.addValidation(validator);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
submitForm = () => {
|
|
22
|
-
this.validate();
|
|
21
|
+
submitForm = async () => {
|
|
22
|
+
let errors = await this.validate();
|
|
23
|
+
console.log(errors);
|
|
24
|
+
if (errors) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
this.args.onSubmit?.();
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
validate = () => {
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
validate = async () => {
|
|
32
|
+
let errors = await this.validations.validate(this.args.model);
|
|
33
|
+
this.errors = errors;
|
|
34
|
+
return errors;
|
|
30
35
|
}
|
|
31
36
|
}
|
package/addon/styles/form.css
CHANGED
|
@@ -13,11 +13,11 @@ export default class ValidationBuilder {
|
|
|
13
13
|
this.validations.push(validator);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
validate(model) {
|
|
16
|
+
async validate(model) {
|
|
17
17
|
let errors = {};
|
|
18
18
|
for (let validator of this.validations) {
|
|
19
19
|
const value = get(model, validator.valuePath);
|
|
20
|
-
validator.validate(value);
|
|
20
|
+
await validator.validate(value);
|
|
21
21
|
if (!validator.isValid) {
|
|
22
22
|
errors[validator.valuePath] = validator.errorMessage;
|
|
23
23
|
}
|