diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index f000fd08..049de497 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -28,6 +28,12 @@ let BookWyrm = new class { this.revealForm.bind(this)) ); + document.querySelectorAll('[data-hides]') + .forEach(button => button.addEventListener( + 'change', + this.hideForm.bind(this)) + ); + document.querySelectorAll('[data-back]') .forEach(button => button.addEventListener( 'click', @@ -119,7 +125,7 @@ let BookWyrm = new class { } /** - * Toggle form. + * Show form. * * @param {Event} event * @return {undefined} @@ -127,10 +133,26 @@ let BookWyrm = new class { revealForm(event) { let trigger = event.currentTarget; let hidden = trigger.closest('.hidden-form').querySelectorAll('.is-hidden')[0]; - - this.addRemoveClass(hidden, 'is-hidden', !hidden); + // if the form has already been revealed, there is no '.is-hidden' element + // so this doesn't really work as a toggle + if (hidden) { + this.addRemoveClass(hidden, 'is-hidden', !hidden); + } } + /** + * Hide form. + * + * @param {Event} event + * @return {undefined} + */ + hideForm(event) { + let trigger = event.currentTarget; + let targetId = trigger.dataset.hides + let visible = document.getElementById(targetId) + this.addRemoveClass(visible, 'is-hidden', true); + } + /** * Execute actions on targets based on triggers. * @@ -227,7 +249,7 @@ let BookWyrm = new class { } /** - * Check or uncheck a checbox. + * Check or uncheck a checkbox. * * @param {string} checkbox - id of the checkbox * @param {boolean} pressed - Is the trigger pressed? diff --git a/bookwyrm/templates/lists/form.html b/bookwyrm/templates/lists/form.html index d2f17d63..a98cae94 100644 --- a/bookwyrm/templates/lists/form.html +++ b/bookwyrm/templates/lists/form.html @@ -18,45 +18,45 @@
{% trans "List curation:" %} -