diff options
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/templates/base.html | 17 |
1 files changed, 12 insertions, 5 deletions
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); </script> {% endif %} </header> |