From caf38275ff3780e11b1ff3d872cdee65def86505 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 2 Aug 2023 21:32:00 +0800 Subject: [PATCH] if it aint empty, excute the function --- static/app.js | 58 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/static/app.js b/static/app.js index a12add3..6a356c3 100755 --- a/static/app.js +++ b/static/app.js @@ -3349,43 +3349,45 @@ function scanNetworks() { } - // UPLOAD CUSTOM STOCK LOGO function uploadStockLogo() { const fileInput_stocks = document.getElementById("stocks-logo-upload-browse"); - const stock_file = fileInput_stocks.files[0]; - const stock_upload_msg = document.getElementById("stocklogoupload"); + if (fileInput_stocks.value !== "") { + const stock_file = fileInput_stocks.files[0]; + const stock_upload_msg = document.getElementById("stocklogoupload"); - const formData_stocks = new FormData(); - formData_stocks.append('file', stock_file) - fetch('/upload_stocks', { - method: 'POST', - body: formData_stocks - }) - stock_upload_msg.style.display = "block"; - setTimeout(function hideElement() { - stock_upload_msg.style.display = "none"; - }, 5000); - fileInput_stocks.value = ""; + const formData_stocks = new FormData(); + formData_stocks.append('file', stock_file) + fetch('/upload_stocks', { + method: 'POST', + body: formData_stocks + }) + stock_upload_msg.style.display = "block"; + setTimeout(function hideElement() { + stock_upload_msg.style.display = "none"; + }, 5000); + fileInput_stocks.value = ""; + } } - // UPLOAD CUSTOM CRYPTO LOGO function uploadCryptoLogo() { const fileInput_crypto = document.getElementById("crypto-logo-upload-browse"); - const crypto_file = fileInput_crypto.files[0]; - const crypto_upload_msg = document.getElementById("cryptologoupload"); + if (fileInput_crypto.value !== "") { + const crypto_file = fileInput_crypto.files[0]; + const crypto_upload_msg = document.getElementById("cryptologoupload"); - const formData_crypto = new FormData(); - formData_crypto.append('file', crypto_file); - fetch('/upload_crypto', { - method: 'POST', - body: formData_crypto - }) - crypto_upload_msg.style.display = "block"; - setTimeout(function hideElement() { - crypto_upload_msg.style.display = "none"; - }, 5000); - fileInput_crypto.value = ""; + const formData_crypto = new FormData(); + formData_crypto.append('file', crypto_file); + fetch('/upload_crypto', { + method: 'POST', + body: formData_crypto + }); + crypto_upload_msg.style.display = "block"; + setTimeout(function hideElement() { + crypto_upload_msg.style.display = "none"; + }, 5000); + fileInput_crypto.value = ""; + } }