@projectcaluma/ember-form 11.0.0-beta.4 → 11.0.0-beta.5
Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# [@projectcaluma/ember-form-v11.0.0-beta.5](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.4...@projectcaluma/ember-form-v11.0.0-beta.5) (2022-02-01)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* **document-validity:** wait to validate until the UI has finished saving values ([9ec5330](https://github.com/projectcaluma/ember-caluma/commit/9ec5330905046604f95ab42985a29a5e0dc369a4))
|
7
|
+
* **form:** use component save task instead of field for loading indicator ([6de510d](https://github.com/projectcaluma/ember-caluma/commit/6de510d19a3608b7cd40092908d562a152ef03bd))
|
8
|
+
|
1
9
|
# [@projectcaluma/ember-form-v11.0.0-beta.4](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.3...@projectcaluma/ember-form-v11.0.0-beta.4) (2022-02-01)
|
2
10
|
|
3
11
|
|
@@ -1,5 +1,9 @@
|
|
1
1
|
{{#if this.visible}}
|
2
|
-
<div
|
2
|
+
<div
|
3
|
+
class="uk-margin"
|
4
|
+
{{did-insert this.registerComponent}}
|
5
|
+
{{will-destroy this.unregisterComponent}}
|
6
|
+
>
|
3
7
|
{{#if this.labelVisible}}
|
4
8
|
<CfField::label @field={{@field}} />
|
5
9
|
{{/if}}
|
@@ -24,11 +28,11 @@
|
|
24
28
|
<div
|
25
29
|
class="cf-field__icon uk-padding-remove-vertical uk-flex uk-flex-middle uk-flex-center"
|
26
30
|
>
|
27
|
-
{{#if
|
31
|
+
{{#if this.save.isRunning}}
|
28
32
|
<UkSpinner class="uk-animation-fade" />
|
29
|
-
{{else if (or
|
33
|
+
{{else if (or this.save.last.isError @field.isInvalid)}}
|
30
34
|
<UkIcon @icon="warning" class="uk-animation-fade uk-text-danger" />
|
31
|
-
{{else if
|
35
|
+
{{else if this.save.last.isSuccessful}}
|
32
36
|
<UkIcon @icon="check" class="uk-animation-fade uk-text-success" />
|
33
37
|
{{/if}}
|
34
38
|
</div>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { getOwner } from "@ember/application";
|
2
|
-
import {
|
2
|
+
import { action } from "@ember/object";
|
3
3
|
import Component from "@glimmer/component";
|
4
4
|
import { timeout, restartableTask } from "ember-concurrency";
|
5
5
|
|
@@ -18,6 +18,16 @@ import { hasQuestionType } from "@projectcaluma/ember-core/helpers/has-question-
|
|
18
18
|
* @argument {Field} field The field data model to render
|
19
19
|
*/
|
20
20
|
export default class CfFieldComponent extends Component {
|
21
|
+
@action
|
22
|
+
registerComponent() {
|
23
|
+
this.args.field._components.add(this);
|
24
|
+
}
|
25
|
+
|
26
|
+
@action
|
27
|
+
unregisterComponent() {
|
28
|
+
this.args.field._components.delete(this);
|
29
|
+
}
|
30
|
+
|
21
31
|
get visible() {
|
22
32
|
return (
|
23
33
|
!this.args.field?.hidden &&
|
@@ -41,8 +51,9 @@ export default class CfFieldComponent extends Component {
|
|
41
51
|
}
|
42
52
|
|
43
53
|
/**
|
44
|
-
* Task to save a field. This will set the passed value to the answer and
|
45
|
-
*
|
54
|
+
* Task to save a field. This will set the passed value to the answer and save
|
55
|
+
* the field to the API after a timeout of 500 milliseconds which intends to
|
56
|
+
* reduce the amount of saved values when changed rapidly.
|
46
57
|
*
|
47
58
|
* @method save
|
48
59
|
* @param {String|Number|String[]} value
|
@@ -57,14 +68,18 @@ export default class CfFieldComponent extends Component {
|
|
57
68
|
yield timeout(500);
|
58
69
|
}
|
59
70
|
|
60
|
-
|
71
|
+
if (this.args.field.answer) {
|
72
|
+
this.args.field.answer.value = value;
|
73
|
+
}
|
61
74
|
|
62
75
|
yield this.args.field.validate.perform();
|
63
76
|
|
64
77
|
try {
|
78
|
+
// Save the new field value unlinked so the fields save task is not
|
79
|
+
// aborted when this component is destroyed
|
65
80
|
return yield this.args.field.save.unlinked().perform();
|
66
81
|
} catch (e) {
|
67
|
-
//
|
82
|
+
// The component was destroyed before the fields save task was finished
|
68
83
|
}
|
69
84
|
}
|
70
85
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { action } from "@ember/object";
|
2
2
|
import Component from "@glimmer/component";
|
3
3
|
import { restartableTask } from "ember-concurrency";
|
4
|
+
import { cached } from "tracked-toolbox";
|
4
5
|
|
5
6
|
/**
|
6
7
|
* Component to check the validity of a document
|
@@ -31,12 +32,26 @@ export default class DocumentValidity extends Component {
|
|
31
32
|
* @argument {Boolean} validateOnEnter
|
32
33
|
*/
|
33
34
|
|
35
|
+
@cached
|
34
36
|
get isValid() {
|
35
|
-
return this.args.document.fields
|
37
|
+
return this.args.document.fields
|
38
|
+
.filter((f) => !f.hidden)
|
39
|
+
.every((f) => f.isValid);
|
36
40
|
}
|
37
41
|
|
38
42
|
@restartableTask
|
39
43
|
*_validate() {
|
44
|
+
const saveTasks = this.args.document.fields
|
45
|
+
.flatMap((field) => [
|
46
|
+
...[...(field._components ?? [])].map((c) => c.save.last),
|
47
|
+
field.save?.last,
|
48
|
+
])
|
49
|
+
.filter(Boolean);
|
50
|
+
|
51
|
+
// Wait until all currently running save tasks in the UI and in the field
|
52
|
+
// itself are finished
|
53
|
+
yield Promise.all(saveTasks);
|
54
|
+
|
40
55
|
for (const field of this.args.document.fields) {
|
41
56
|
yield field.validate.linked().perform();
|
42
57
|
}
|
package/addon/lib/field.js
CHANGED
@@ -152,6 +152,16 @@ export default class Field extends Base {
|
|
152
152
|
*/
|
153
153
|
@tracked _errors = [];
|
154
154
|
|
155
|
+
/**
|
156
|
+
* Currently rendered field components that use this field. This is used in
|
157
|
+
* the document validity component to await all current save tasks before
|
158
|
+
* validating.
|
159
|
+
*
|
160
|
+
* @property {Set} _components
|
161
|
+
* @private
|
162
|
+
*/
|
163
|
+
_components = new Set();
|
164
|
+
|
155
165
|
/**
|
156
166
|
* The primary key of the field. Consists of the document and question primary
|
157
167
|
* keys.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@projectcaluma/ember-form",
|
3
|
-
"version": "11.0.0-beta.
|
3
|
+
"version": "11.0.0-beta.5",
|
4
4
|
"description": "Ember addon for rendering Caluma forms.",
|
5
5
|
"keywords": [
|
6
6
|
"ember-addon"
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"@embroider/test-setup": "1.0.0",
|
46
46
|
"@faker-js/faker": "6.0.0-alpha.5",
|
47
47
|
"@projectcaluma/ember-testing": "10.2.0-beta.2",
|
48
|
-
"@projectcaluma/ember-workflow": "11.0.0-beta.
|
48
|
+
"@projectcaluma/ember-workflow": "11.0.0-beta.3",
|
49
49
|
"broccoli-asset-rev": "3.0.0",
|
50
50
|
"ember-cli": "3.28.5",
|
51
51
|
"ember-cli-code-coverage": "1.0.3",
|