Skip to content

Commit

Permalink
fix: hide this feature behind a config flag
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke authored and czosel committed Feb 3, 2022
1 parent 171fdad commit 52bc19f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions addon/components/validated-form.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOwner } from "@ember/application";
import { action } from "@ember/object";
import { scheduleOnce } from "@ember/runloop";
import Component from "@glimmer/component";
Expand All @@ -14,6 +15,10 @@ export default class ValidatedFormComponent extends Component {

constructor(...args) {
super(...args);
this.config =
getOwner(this).resolveRegistration("config:environment")[
"ember-validated-form"
];

if (this.args.model && this.args.model.validate) {
scheduleOnce("actions", this, "validateModel", this.args.model);
Expand Down Expand Up @@ -44,9 +49,10 @@ export default class ValidatedFormComponent extends Component {
await model.validate();

if (model.get("isInvalid")) {
const firstError = model.errors[0];
if (firstError?.key) {
document.querySelector(`[name=${firstError.key}]`)?.scrollIntoView();
if (this.config?.scrollErrorIntoView && model.errors[0]?.key) {
document
.querySelector(`[name=${model.errors[0].key}]`)
?.scrollIntoView();
}
this.runCallback(PROP_ON_INVALID_SUBMIT);
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function (environment) {
historySupportMiddleware: true,
"ember-validated-form": {
theme: "bootstrap",
scrollErrorIntoView: false,
defaults: {
hint: "permanent-custom-hint",
},
Expand Down

0 comments on commit 52bc19f

Please sign in to comment.