cryptovalidate portfolio

This commit is contained in:
Justin 2023-03-17 18:06:29 +08:00 committed by GitHub
parent d5924082d7
commit f4281d10fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2100,10 +2100,13 @@ var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
let x = document.getElementById("inputText4").value;
let baseCurrency = x.split(",")[1];
// console.log(baseCurrency)
let portfolioCheckbox = document.getElementById("crypto_portfolio_checkbox");
let sharesText = document.getElementById("cryptoshares").value;
let averageCost = document.getElementById("cryptocost").value;
let dateText = document.getElementById("cryptodate").value;
let text;
let text2;
if (x.toUpperCase() != x) {
document.getElementById('demo2').style.display = "block";
text = "Crypto and base must be uppercase";
@ -2115,21 +2118,18 @@ var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
text = "No blanks"
// createLi = false;
}
else if (x.includes(' ')) {
text = "No spaces";
document.getElementById('demo2').style.display = "block";
document.getElementById("inputText4").value = '';
// createLi = false;
}
else if (specialChars.test(x)) {
document.getElementById('demo2').style.display = "block";
text = "No special characters allowed";
document.getElementById("inputText4").value = '';
// createLi = false;
}
else if (!x.includes(',')) {
document.getElementById('demo2').style.display = "block";
document.getElementById("inputText4").value = '';
@ -2147,12 +2147,85 @@ var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
else {
text = "Input OK";
document.getElementById('demo2').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
setTimeout(
function() {
document.getElementById('inputText4').value="";
}, 100);
//PORTFOLIO VALIDATION HERE
if (portfolioCheckbox.checked) {
if ((sharesText === ' ') || (averageCost === ' ') || (dateText === ' ')) {
text2 = "No spaces";
document.getElementById('demo-portfolio-crypto').style.display = "block";
document.getElementById("cryptoshares").value = '';
document.getElementById("cryptocost").value = '';
document.getElementById("cryptodate").value = '';
document.getElementById("inputText4").value = '';
}
else if ((isNaN(sharesText))|| (isNaN(averageCost))) {
text2 = "No text characters, only numbers";
document.getElementById('demo-portfolio-crypto').style.display = "block";
document.getElementById("cryptoshares").value = '';
document.getElementById("cryptocost").value = '';
document.getElementById("cryptodate").value = '';
document.getElementById("inputText4").value = '';
}
else if ((!dateText.includes('-')) && (dateText !== '')) {
text2 = "Incorrect date format, it should be YYYY-MM-DD";
document.getElementById('demo-portfolio-crypto').style.display = "block";
document.getElementById("cryptoshares").value = '';
document.getElementById("cryptocost").value = '';
document.getElementById("cryptodate").value = '';
document.getElementById("inputText4").value = '';
}
else if (((sharesText !== '') || (averageCost !== '') || (dateText !== '')) && ((sharesText === '') || (averageCost === '') || (dateText === ''))) {
text2 = "Some fields are empty";
document.getElementById('demo-portfolio-crypto').style.display = "block";
document.getElementById("cryptoshares").value = '';
document.getElementById("cryptocost").value = '';
document.getElementById("cryptodate").value = '';
document.getElementById("inputText4").value = '';
}
else {
text2 = "Input OK";
document.getElementById('demo-portfolio-crypto').style.display = "none";
createLi = true;
let cost = document.getElementById('cryptocost').value;
let shares = document.getElementById('cryptoshares').value;
let symbol = document.getElementById('inputText4').value;
let days = document.getElementById('cryptodate').value;
let settings = {
shares:shares,
cost:cost,
symbol:symbol,
days:days,
};
console.log(JSON.stringify(settings));
setTimeout(
function() {
document.getElementById('inputText4').value="";
document.getElementById("cryptocost").value = '';
document.getElementById("cryptoshares").value = '';
document.getElementById("cryptodate").value = '';
document.getElementById("inputText4").value = '';
}, 100);
if ((sharesText !== '') && (averageCost !== '') && (dateText !== '')) {
fetch("/savePortfolioCryptoSettings", {
method: "POST",
body: JSON.stringify(settings),
});
}
}
document.getElementById("demo-portfolio-crypto").innerHTML = text2;
}
else {
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
setTimeout(
function() {
document.getElementById('inputText4').value="";
}, 100);
}
}
document.getElementById("demo2").innerHTML = text;
}