From 87ec3a2be3693c78415e2812306b71f0d3951eb9 Mon Sep 17 00:00:00 2001 From: Falk Date: Mon, 31 Jan 2022 11:56:16 +0100 Subject: [PATCH] docs: enable and document feature flag --- addon/components/validated-form.js | 2 +- tests/dummy/app/snippets/config-features.js | 10 ++++++++++ tests/dummy/app/templates/docs/configuration.md | 7 +++++++ tests/dummy/config/environment.js | 4 +++- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/dummy/app/snippets/config-features.js diff --git a/addon/components/validated-form.js b/addon/components/validated-form.js index 51b0c79a..68340e37 100644 --- a/addon/components/validated-form.js +++ b/addon/components/validated-form.js @@ -49,7 +49,7 @@ export default class ValidatedFormComponent extends Component { await model.validate(); if (model.get("isInvalid")) { - if (this.config?.scrollErrorIntoView && model.errors[0]?.key) { + if (this.config?.features?.scrollErrorIntoView && model.errors[0]?.key) { document .querySelector(`[name=${model.errors[0].key}]`) ?.scrollIntoView(); diff --git a/tests/dummy/app/snippets/config-features.js b/tests/dummy/app/snippets/config-features.js new file mode 100644 index 00000000..6830de22 --- /dev/null +++ b/tests/dummy/app/snippets/config-features.js @@ -0,0 +1,10 @@ +var ENV = { + // ... + "ember-validated-form": { + theme: "bootstrap", + features: { + scrollErrorIntoView: true, + } + }, + // ... +}; diff --git a/tests/dummy/app/templates/docs/configuration.md b/tests/dummy/app/templates/docs/configuration.md index 13ca2b0d..4c720062 100644 --- a/tests/dummy/app/templates/docs/configuration.md +++ b/tests/dummy/app/templates/docs/configuration.md @@ -33,3 +33,10 @@ For instance: {{demo.snippet 'permanent-custom-hint-component-template.hbs' label='permanent-custom-hint.hbs'}} {{/docs-demo}} + +## Other features + +If you want to scroll the first invalid field into view, you can set the +`scrollErrorIntoView` property to `true` (default: false). + +{{docs-snippet name='config-features.js' title='config/environment.js'}} diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index b75ee816..8d2ac59e 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -9,10 +9,12 @@ module.exports = function (environment) { historySupportMiddleware: true, "ember-validated-form": { theme: "bootstrap", - scrollErrorIntoView: false, defaults: { hint: "permanent-custom-hint", }, + features: { + scrollErrorIntoView: false, + }, }, EmberENV: { FEATURES: {