Skip to content

Commit 47a7fe0

Browse files
committed
remove computed property and refactor to native class
1 parent 7c0149c commit 47a7fe0

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
import { notEmpty } from '@ember/object/computed';
2-
import { defineProperty, computed } from '@ember/object';
3-
import { A } from '@ember/array';
41
import BsFormElement from 'ember-bootstrap/components/bs-form/element';
52

6-
export default BsFormElement.extend({
7-
'__ember-bootstrap_subclass' : true,
3+
export default class BsFormElementWithChangesetValidationsSupport extends BsFormElement {
4+
'__ember-bootstrap_subclass' = true;
85

9-
hasValidator: notEmpty('model.validate'),
6+
get errors() {
7+
return [
8+
this.model.error[this.property]?.validation
9+
];
10+
}
1011

11-
setupValidations() {
12-
// `Changeset.error` is a getter based on a tracked property. Since it's a
13-
// derived state it's not working together with computed properties smoothly.
14-
// As a work-a-round we observe the `Changeset._errors` computed property
15-
// directly, which holds the state. This is not optimal cause it's private.
16-
// Should refactor to native getter as soon as `<FormElement>` component
17-
// of Ember Bootstrap supports native getters for `FormElement.errors`
18-
// property.
19-
let key = `model.error.${this.get('property')}.validation`;
20-
defineProperty(this, 'errors', computed(`model._errors`, function() {
21-
return A(this.get(key));
22-
}));
12+
get hasValidator() {
13+
return typeof this.model.validate === 'function';
2314
}
24-
});
15+
}

0 commit comments

Comments
 (0)