Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert extended Form to native class, providing compatibility with ember-bootstrap 5.1+ #42

Merged
merged 1 commit into from Apr 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions addon/components/bs-form.js
@@ -1,24 +1,24 @@
import { notEmpty } from '@ember/object/computed';
import { assert } from '@ember/debug';
import RSVP from 'rsvp';
import BsForm from 'ember-bootstrap/components/bs-form';

export default BsForm.extend({
'__ember-bootstrap_subclass': true,
export default class BsFormWithChangesetValidationsSupport extends BsForm {
'__ember-bootstrap_subclass' = true;

hasValidator: notEmpty('model.validate'),
get hasValidator() {
return typeof this.model?.validate === 'function';
}

validate(model) {
async validate(model) {
let m = model;

assert(
'Model must be a Changeset instance',
m && typeof m.validate === 'function'
);
return new RSVP.Promise(function (resolve, reject) {
m.validate().then(() => {
model.get('isValid') ? resolve() : reject();
}, reject);
});
},
});

await m.validate();
if (!model.get('isValid')) {
throw new Error();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a meaningful error message? I know we haven't had one before. Just noticed when reviewing. So not required for this one to be merged.

}
}
}