linting, review changes

This commit is contained in:
wrenny-ko 2024-08-27 18:38:14 -04:00
parent 877b3a002e
commit 9b99b17cea
2 changed files with 28 additions and 16 deletions

View file

@ -67,6 +67,14 @@ describe('Image upload form', () => {
if (!fetchButton.hasAttribute('disabled')) throw new Error('fetchButton is not disabled'); if (!fetchButton.hasAttribute('disabled')) throw new Error('fetchButton is not disabled');
}; };
const assertSubmitButtonIsDisabled = () => {
if (!submitButton.hasAttribute('disabled')) throw new Error('submitButton is not disabled');
};
const assertSubmitButtonIsEnabled = () => {
if (submitButton.hasAttribute('disabled')) throw new Error('submitButton is disabled');
};
beforeEach(() => { beforeEach(() => {
document.documentElement.insertAdjacentHTML( document.documentElement.insertAdjacentHTML(
'beforeend', 'beforeend',
@ -98,7 +106,7 @@ describe('Image upload form', () => {
sourceEl = assertNotNull($<HTMLInputElement>('.js-source-url')); sourceEl = assertNotNull($<HTMLInputElement>('.js-source-url'));
descrEl = assertNotNull($<HTMLTextAreaElement>('.js-image-descr-input')); descrEl = assertNotNull($<HTMLTextAreaElement>('.js-image-descr-input'));
fetchButton = assertNotNull($<HTMLButtonElement>('#js-scraper-preview')); fetchButton = assertNotNull($<HTMLButtonElement>('#js-scraper-preview'));
submitButton = assertNotNull($<HTMLButtonElement>('.actions > .button')) submitButton = assertNotNull($<HTMLButtonElement>('.actions > .button'));
setupImageUpload(); setupImageUpload();
fetchMock.resetMocks(); fetchMock.resetMocks();

View file

@ -183,6 +183,8 @@ function setupImageUpload() {
$$('.tag-error').forEach(el => el.remove()); $$('.tag-error').forEach(el => el.remove());
} }
const ratingsTags = ['safe', 'suggestive', 'questionable', 'explicit', 'semi-grimdark', 'grimdark', 'grotesque'];
// populate tag error helper bars as necessary // populate tag error helper bars as necessary
// return true if all checks pass // return true if all checks pass
// return false if any check fails // return false if any check fails
@ -195,7 +197,6 @@ function setupImageUpload() {
const tagsArr = tagInput.value.split(',').map(t => t.trim()); const tagsArr = tagInput.value.split(',').map(t => t.trim());
const ratingsTags = ['safe', 'suggestive', 'questionable', 'explicit', 'semi-grimdark', 'grimdark', 'grotesque'];
const errors = []; const errors = [];
let hasRating = false; let hasRating = false;
@ -250,29 +251,32 @@ function setupImageUpload() {
function anchorToTop() { function anchorToTop() {
let url = window.location.href; let url = window.location.href;
url = url.split('#')[0]; //remove any existing hash anchor from url url = url.split('#')[0]; //remove any existing hash anchor from url
url += '#'; //move view to top of page url += '#taginput-fancy-tag_input'; //move view to tags input
window.location.href = url; window.location.href = url;
} }
function submitHandler(event) { function submitHandler(event) {
clearTagErrors(); // remove any existing tag error elements // Remove any existing tag error elements
clearTagErrors();
if (validateTags() === true) { if (validateTags()) {
// tags valid; // Disable navigation check
unregisterBeforeUnload(); unregisterBeforeUnload();
// allow form submission // Prevent duplicate attempts to submit the form
disableUploadButton(); disableUploadButton();
return true;
// Let the form submission complete
} else {
// Scroll to the top of page to see validation errors
anchorToTop();
// allow users to re-submit the form
enableUploadButton();
// Prevent the form from being submitted
event.preventDefault();
} }
//tags invalid
enableUploadButton(); // enable Upload button
anchorToTop(); // move view to top of page
// prevent form submission
event.preventDefault();
return false;
} }
fileField.addEventListener('change', registerBeforeUnload); fileField.addEventListener('change', registerBeforeUnload);