Skip to content

Commit 2ebb518

Browse files
authored
Merge pull request #42 from kaliber5/native-form-class
Convert extended Form to native class, providing compatibility with ember-bootstrap 5.1+
2 parents d407954 + 8095a72 commit 2ebb518

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

addon/components/bs-form.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { notEmpty } from '@ember/object/computed';
21
import { assert } from '@ember/debug';
3-
import RSVP from 'rsvp';
42
import BsForm from 'ember-bootstrap/components/bs-form';
53

6-
export default BsForm.extend({
7-
'__ember-bootstrap_subclass': true,
4+
export default class BsFormWithChangesetValidationsSupport extends BsForm {
5+
'__ember-bootstrap_subclass' = true;
86

9-
hasValidator: notEmpty('model.validate'),
7+
get hasValidator() {
8+
return typeof this.model?.validate === 'function';
9+
}
1010

11-
validate(model) {
11+
async validate(model) {
1212
let m = model;
1313

1414
assert(
1515
'Model must be a Changeset instance',
1616
m && typeof m.validate === 'function'
1717
);
18-
return new RSVP.Promise(function (resolve, reject) {
19-
m.validate().then(() => {
20-
model.get('isValid') ? resolve() : reject();
21-
}, reject);
22-
});
23-
},
24-
});
18+
19+
await m.validate();
20+
if (!model.get('isValid')) {
21+
throw new Error();
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)