scroll instead of anchor, closed button tags

This commit is contained in:
wrenny-ko 2024-08-27 18:52:11 -04:00
parent 9b99b17cea
commit b7733a2ae5
2 changed files with 13 additions and 9 deletions

View file

@ -88,10 +88,10 @@ describe('Image upload form', () => {
<input id="image_sources_0_source" name="image[sources][0][source]" type="text" class="js-source-url" />
<textarea id="image_tag_input" name="image[tag_input]" class="js-image-tags-input"></textarea>
<div class="js-taginput" value="safe, pony, third tag"/>
<button id="tagsinput-save" type="button" class="button"/>
<button id="tagsinput-save" type="button" class="button">Save</button>
<textarea id="image_description" name="image[description]" class="js-image-descr-input"></textarea>
<div class="actions">
<button class="button" type="submit"/>
<button class="button" type="submit">Upload</button>
</div>
</form>`,
);

View file

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