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();