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

support Ember Bootstrap v4.5 and above; drop support for older versions #34

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ further details.
Compatibility
------------------------------------------------------------------------------

* Ember Bootstrap v3
* Ember Bootstrap v4.5 or above
* Ember Changeset and Ember Changeset Validations v3
* Ember.js v3.16 or above
* Ember CLI v2.13 or above
Expand Down
24 changes: 7 additions & 17 deletions addon/components/bs-form/element.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import BsFormElement from 'ember-bootstrap/components/bs-form/element';
import { action, get } from '@ember/object';
import { dependentKeyCompat } from '@ember/object/compat';
import { isNone, typeOf } from '@ember/utils';

export default class BsFormElementWithChangesetValidationsSupport extends BsFormElement {
'__ember-bootstrap_subclass' = true;

// We convert
//
// `model.error.${this.property}.validation` which could be either a string or an array
// see https://github.com/validated-changeset/validated-changeset/#error
//
// into
//
// Ember Bootstrap expects errors property of FormElement to be an array of validation messages:
// see https://www.ember-bootstrap.com/api/classes/Components.FormElement.html#property_errors
//
// If the if the property is valid but no validation is present `model.error.[this.property] could also be undefined.
@dependentKeyCompat
get errors() {
let errors = get(this, `model.error.${this.property}.validation`);
let { model, property } = this.args;

// must use `get` method to support nested properties
let errors = get(model, `error.${property}.validation`);

// no messages
if (isNone(errors)) {
Expand All @@ -36,7 +26,7 @@ export default class BsFormElementWithChangesetValidationsSupport extends BsForm
}

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

// Ember Changeset does not validate the initial state. Properties are not
Expand Down Expand Up @@ -71,10 +61,10 @@ export default class BsFormElementWithChangesetValidationsSupport extends BsForm

// run initial validation if
// - visibility of validations changed
let canValidate = this.hasValidator && this.property;
let canValidate = this.hasValidator && this.args.property;
let validationVisibilityChanged = !validationShowBefore && this.showOwnValidation;
if (canValidate && validationVisibilityChanged) {
await this.model.validate(this.property);
await this.args.model.validate(this.args.property);
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"bootstrap": "^4.3.1",
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^1.5.3",
"ember-bootstrap": "^3.1.1",
"ember-bootstrap": "^4.5.0",
"ember-cli": "~3.16.0",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-eslint": "^5.1.0",
Expand Down