scroll to tag block, review suggestions, cleanup

This commit is contained in:
wrenny-ko 2024-08-29 18:35:20 -04:00
parent 4010a8a277
commit 343078678a

View file

@ -2,6 +2,7 @@
* Fetch and display preview images for various image upload forms. * Fetch and display preview images for various image upload forms.
*/ */
import { assertNotNull } from './utils/assert';
import { fetchJson, handleError } from './utils/requests'; import { fetchJson, handleError } from './utils/requests';
import { $, $$, clearEl, hideEl, makeEl, showEl } from './utils/dom'; import { $, $$, clearEl, hideEl, makeEl, showEl } from './utils/dom';
import { addTag } from './tagsinput'; import { addTag } from './tagsinput';
@ -173,9 +174,8 @@ function setupImageUpload() {
function createTagError(message) { function createTagError(message) {
const buttonAfter = $('#tagsinput-save'); const buttonAfter = $('#tagsinput-save');
const errorElement = makeEl('span', { className: 'help-block tag-error' }); const errorElement = makeEl('span', { className: 'help-block tag-error', innerText: message });
errorElement.innerText = message;
buttonAfter.insertAdjacentElement('beforebegin', errorElement); buttonAfter.insertAdjacentElement('beforebegin', errorElement);
} }
@ -229,14 +229,6 @@ function setupImageUpload() {
return errors.length === 0; // true: valid if no errors return errors.length === 0; // true: valid if no errors
} }
function enableUploadButton() {
const submitButton = $('.input--separate-top');
if (submitButton !== null) {
submitButton.disabled = false;
submitButton.innerText = 'Upload';
}
}
function disableUploadButton() { function disableUploadButton() {
const submitButton = $('.button.input--separate-top'); const submitButton = $('.button.input--separate-top');
if (submitButton !== null) { if (submitButton !== null) {
@ -248,17 +240,6 @@ function setupImageUpload() {
requestAnimationFrame(() => submitButton.setAttribute('disabled', 'disabled')); requestAnimationFrame(() => submitButton.setAttribute('disabled', 'disabled'));
} }
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) { function submitHandler(event) {
// Remove any existing tag error elements // Remove any existing tag error elements
clearTagErrors(); clearTagErrors();
@ -273,10 +254,7 @@ function setupImageUpload() {
// Let the form submission complete // Let the form submission complete
} else { } else {
// Scroll to view validation errors // Scroll to view validation errors
scrollToTags(); assertNotNull($('.fancy-tag-upload')).scrollIntoView();
// allow users to re-submit the form
enableUploadButton();
// Prevent the form from being submitted // Prevent the form from being submitted
event.preventDefault(); event.preventDefault();