From b614fcdb8579ba29fccfa47eab1e2965cfb0beaa Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 21 Oct 2019 21:14:13 -0700 Subject: Fix regression: Can't remove videos from local playlists --- youtube/templates/base.html | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'youtube/templates/base.html') diff --git a/youtube/templates/base.html b/youtube/templates/base.html index ac5c1ce..554e116 100644 --- a/youtube/templates/base.html +++ b/youtube/templates/base.html @@ -142,9 +142,19 @@ window.setTimeout(removeMessage, removalDelay+300, messageBox); } // https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_forms_through_JavaScript - function sendData(){ + function sendData(event){ + var clicked_button = document.activeElement; + if(clicked_button === null || clicked_button.getAttribute('type') !== 'submit' || clicked_button.parentElement != event.target){ + console.log('ERROR: clicked_button not valid'); + return; + } + if(clicked_button.getAttribute('value') !== 'add'){ + return; // video(s) are being removed from playlist, just let it refresh the page + } + event.preventDefault(); var XHR = new XMLHttpRequest(); var FD = new FormData(playlistAddForm); + // https://stackoverflow.com/questions/48322876/formdata-doesnt-include-value-of-buttons FD.append('action', 'add'); @@ -168,10 +178,7 @@ XHR.send(FD); } - playlistAddForm.addEventListener('submit', function(event){ - event.preventDefault(); - sendData(); - }); + playlistAddForm.addEventListener('submit', sendData); {% endif %} -- cgit v1.2.3