update stock and crypto position validation fixed

This commit is contained in:
Justin 2023-07-11 22:21:42 +08:00 committed by GitHub
parent 17729b184f
commit d55f2109c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2951,7 +2951,42 @@ function updateStockPorftolio() {
days:update_stock_days, days:update_stock_days,
}; };
if ((update_stock_shares !== '') && (update_stock_cost !== '') && (update_stock_days !== '') && (update_symbol !== '')) { if ((update_symbol === '') || (update_symbol === ' ')) {
document.getElementById('stockremoved-p').innerHTML = 'No symbol selected.';
document.getElementById('removed-stock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-stock-p').style.display = "none";
}, 5000);
}
else if ((update_stock_cost === ' ') || (update_stock_shares === ' ') || (update_stock_days === ' ')) {
document.getElementById('stockremoved-p').innerHTML = 'No spaces.';
document.getElementById('removed-stock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-stock-p').style.display = "none";
}, 5000);
}
else if ((isNaN(update_stock_cost)) || (isNaN(update_stock_shares))) {
document.getElementById('stockremoved-p').innerHTML = 'No text characters, only numbers.';
document.getElementById('removed-stock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-stock-p').style.display = "none";
}, 5000);
}
else if ((!update_stock_days.includes('-')) && (update_stock_days !== '')) {
document.getElementById('stockremoved-p').innerHTML = 'Incorrect date format, it should be YYYY-MM-DD';
document.getElementById('removed-stock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-stock-p').style.display = "none";
}, 5000);
}
else if (((update_stock_shares !== '') || (update_stock_cost !== '') || (update_stock_days !== '')) && ((update_stock_shares === '') || (update_stock_cost === '') || (update_stock_days === ''))) {
document.getElementById('stockremoved-p').innerHTML = 'Some fields are empty.';
document.getElementById('removed-stock-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-stock-p').style.display = "none";
}, 5000);
}
else {
fetch("/savePortfolioSettings", { fetch("/savePortfolioSettings", {
method: "POST", method: "POST",
body: JSON.stringify(update_stock_settings), body: JSON.stringify(update_stock_settings),
@ -2961,9 +2996,6 @@ function updateStockPorftolio() {
setTimeout(function hideElement() { setTimeout(function hideElement() {
document.getElementById('updated-stock-p').style.display = "none"; document.getElementById('updated-stock-p').style.display = "none";
}, 5000); }, 5000);
} else {
stockValidate();
} }
} }
@ -3016,7 +3048,42 @@ function updateCryptoPorftolio() {
days:update_crypto_days, days:update_crypto_days,
}; };
if ((update_crypto_shares !== '') && (update_crypto_cost !== '') && (update_crypto_days !== '') && (update_crypto_symbol !== '')) { if ((update_crypto_symbol === '') || (update_crypto_symbol === ' ')) {
document.getElementById('cryptoremoved-p').innerHTML = 'No symbol selected.';
document.getElementById('removed-crypto-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-crypto-p').style.display = "none";
}, 5000);
}
else if ((update_crypto_cost === ' ') || (update_crypto_shares === ' ') || (update_crypto_days === ' ')) {
document.getElementById('cryptoremoved-p').innerHTML = 'No spaces.';
document.getElementById('removed-crypto-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-crypto-p').style.display = "none";
}, 5000);
}
else if ((isNaN(update_crypto_cost)) || (isNaN(update_crypto_shares))) {
document.getElementById('cryptoremoved-p').innerHTML = 'No text characters, only numbers.';
document.getElementById('removed-crypto-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-crypto-p').style.display = "none";
}, 5000);
}
else if ((!update_crypto_days.includes('-')) && (update_crypto_days !== '')) {
document.getElementById('cryptoremoved-p').innerHTML = 'Incorrect date format, it should be YYYY-MM-DD';
document.getElementById('removed-crypto-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-crypto-p').style.display = "none";
}, 5000);
}
else if (((update_crypto_shares !== '') || (update_crypto_cost !== '') || (update_crypto_days !== '')) && ((update_crypto_shares === '') || (update_crypto_cost === '') || (update_crypto_days === ''))) {
document.getElementById('cryptoremoved-p').innerHTML = 'Some fields are empty.';
document.getElementById('removed-crypto-p').style.display = "block";
setTimeout(function hideElement() {
document.getElementById('removed-crypto-p').style.display = "none";
}, 5000);
}
else {
fetch("/savePortfolioCryptoSettings", { fetch("/savePortfolioCryptoSettings", {
method: "POST", method: "POST",
body: JSON.stringify(update_crypto_settings), body: JSON.stringify(update_crypto_settings),
@ -3026,9 +3093,5 @@ function updateCryptoPorftolio() {
setTimeout(function hideElement() { setTimeout(function hideElement() {
document.getElementById('updated-crypto-p').style.display = "none"; document.getElementById('updated-crypto-p').style.display = "none";
}, 5000); }, 5000);
} else {
cryptoValidate();
} }
} }