Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions addon/components/bs-form.js
Original file line number Diff line number Diff line change
@@ -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.

}
}
}