updated stocks validation to include portfolio. flask integration
This commit is contained in:
parent
f63e221be4
commit
9b9ca1c153
100
static/app.js
100
static/app.js
@ -1955,7 +1955,13 @@ function stockValidate() {
|
||||
var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/;
|
||||
|
||||
let x = document.getElementById("inputText3").value;
|
||||
let portfolioCheckbox = document.getElementById("flexCheckChecked4");
|
||||
let sharesText = document.getElementById("inputText8").value;
|
||||
let averageCost = document.getElementById("inputText9").value;
|
||||
let dateText = document.getElementById("inputText10").value;
|
||||
|
||||
let text;
|
||||
let text2;
|
||||
if (x.toUpperCase() != x) {
|
||||
document.getElementById('demo').style.display = "block";
|
||||
text = "Stock symbol must be uppercase";
|
||||
@ -1967,23 +1973,19 @@ var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/;
|
||||
document.getElementById('demo').style.display = "block";
|
||||
text = "No blanks"
|
||||
// createLi = false;
|
||||
|
||||
}
|
||||
|
||||
else if (x.includes(' ')) {
|
||||
text = "No spaces";
|
||||
document.getElementById('demo').style.display = "block";
|
||||
document.getElementById("inputText3").value = '';
|
||||
// createLi = false;
|
||||
}
|
||||
|
||||
else if (x.length > 5) {
|
||||
document.getElementById('demo').style.display = "block";
|
||||
text = "No more than 5 characters";
|
||||
document.getElementById("inputText3").value = '';
|
||||
// createLi = false;
|
||||
}
|
||||
|
||||
else if (/\d/.test(x)) {
|
||||
document.getElementById('demo').style.display = "block";
|
||||
text = "No numbers allowed";
|
||||
@ -1991,24 +1993,96 @@ var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/;
|
||||
// createLi = false;
|
||||
}
|
||||
// CAREFUL TO DELETE THE BACKEND LIST ITEMS, JUST DELETING THE VALUE LIKE THIS ISN"T 100% ACCURATE
|
||||
|
||||
else if (specialChars.test(x)) {
|
||||
document.getElementById('demo').style.display = "block";
|
||||
text = "No special characters allowed";
|
||||
document.getElementById("inputText3").value = '';
|
||||
// createLi = false;
|
||||
}
|
||||
|
||||
else {
|
||||
text = "Input OK";
|
||||
document.getElementById('demo').style.display = "none";
|
||||
createLi = true;
|
||||
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
|
||||
// addingItems();
|
||||
setTimeout(
|
||||
function() {
|
||||
document.getElementById('inputText3').value="";
|
||||
}, 100);
|
||||
//PORTFOLIO VALIDATION HERE
|
||||
if (portfolioCheckbox.checked) {
|
||||
if ((sharesText === ' ') || (averageCost === ' ') || (dateText === ' ')) {
|
||||
text2 = "No spaces";
|
||||
document.getElementById('demo-portfolio').style.display = "block";
|
||||
document.getElementById("inputText8").value = '';
|
||||
document.getElementById("inputText9").value = '';
|
||||
document.getElementById("inputText10").value = '';
|
||||
document.getElementById("inputText3").value = '';
|
||||
}
|
||||
else if ((isNaN(sharesText))|| (isNaN(averageCost))) {
|
||||
text2 = "No text characters, only numbers";
|
||||
document.getElementById('demo-portfolio').style.display = "block";
|
||||
document.getElementById("inputText8").value = '';
|
||||
document.getElementById("inputText9").value = '';
|
||||
document.getElementById("inputText10").value = '';
|
||||
document.getElementById("inputText3").value = '';
|
||||
}
|
||||
else if ((!dateText.includes('-')) && (dateText !== '')) {
|
||||
text2 = "Incorrect date format, it should be YYYY-MM-DD";
|
||||
document.getElementById('demo-portfolio').style.display = "block";
|
||||
document.getElementById("inputText8").value = '';
|
||||
document.getElementById("inputText9").value = '';
|
||||
document.getElementById("inputText10").value = '';
|
||||
document.getElementById("inputText3").value = '';
|
||||
}
|
||||
else if (((sharesText !== '') || (averageCost !== '') || (dateText !== '')) && ((sharesText === '') || (averageCost === '') || (dateText === ''))) {
|
||||
text2 = "Some fields are empty";
|
||||
document.getElementById('demo-portfolio').style.display = "block";
|
||||
document.getElementById("inputText8").value = '';
|
||||
document.getElementById("inputText9").value = '';
|
||||
document.getElementById("inputText10").value = '';
|
||||
document.getElementById("inputText3").value = '';
|
||||
}
|
||||
else {
|
||||
text2 = "Input OK";
|
||||
document.getElementById('demo-portfolio').style.display = "none";
|
||||
createLi = true;
|
||||
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
|
||||
// addingItems();
|
||||
let cost = document.getElementById('inputText9').value;
|
||||
let shares = document.getElementById('inputText8').value;
|
||||
let symbol = document.getElementById('inputText3').value;
|
||||
let days = document.getElementById('inputText10').value;
|
||||
|
||||
let settings = {
|
||||
shares:shares,
|
||||
cost:cost,
|
||||
symbol:symbol,
|
||||
days:days,
|
||||
};
|
||||
console.log(JSON.stringify(settings));
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
document.getElementById('inputText3').value="";
|
||||
document.getElementById("inputText8").value = '';
|
||||
document.getElementById("inputText9").value = '';
|
||||
document.getElementById("inputText10").value = '';
|
||||
document.getElementById("inputText3").value = '';
|
||||
}, 100);
|
||||
|
||||
if ((sharesText !== '') && (averageCost !== '') && (dateText !== '')) {
|
||||
fetch("/savePortfolioSettings", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(settings),
|
||||
});
|
||||
}
|
||||
}
|
||||
document.getElementById("demo-portfolio").innerHTML = text2;
|
||||
}
|
||||
|
||||
else {
|
||||
createLi = true;
|
||||
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
|
||||
// addingItems();
|
||||
setTimeout(
|
||||
function() {
|
||||
document.getElementById('inputText3').value="";
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
document.getElementById("demo").innerHTML = text;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user