From b7733a2ae5e559aa172254486c4ccc3c6c439772 Mon Sep 17 00:00:00 2001 From: wrenny-ko Date: Tue, 27 Aug 2024 18:52:11 -0400 Subject: [PATCH] scroll instead of anchor, closed button tags --- assets/js/__tests__/upload.spec.ts | 4 ++-- assets/js/upload.js | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/assets/js/__tests__/upload.spec.ts b/assets/js/__tests__/upload.spec.ts index 549af81f..ec0b986a 100644 --- a/assets/js/__tests__/upload.spec.ts +++ b/assets/js/__tests__/upload.spec.ts @@ -88,10 +88,10 @@ describe('Image upload form', () => {
-
-
`, ); diff --git a/assets/js/upload.js b/assets/js/upload.js index c904379d..8153fad8 100644 --- a/assets/js/upload.js +++ b/assets/js/upload.js @@ -248,11 +248,15 @@ function setupImageUpload() { requestAnimationFrame(() => submitButton.setAttribute('disabled', 'disabled')); } - function anchorToTop() { - let url = window.location.href; - url = url.split('#')[0]; //remove any existing hash anchor from url - url += '#taginput-fancy-tag_input'; //move view to tags input - window.location.href = url; + function scrollToTags() { + const taginputEle = $('#taginput-fancy-tag_input'); + + if (!taginputEle) { + // default to scroll to top + window.scrollTo({ top: 0, left: 0 }); + } + + taginputEle.scrollIntoView(); } function submitHandler(event) { @@ -268,8 +272,8 @@ function setupImageUpload() { // Let the form submission complete } else { - // Scroll to the top of page to see validation errors - anchorToTop(); + // Scroll to view validation errors + scrollToTags(); // allow users to re-submit the form enableUploadButton();