globalstock validation
This commit is contained in:
parent
f1c01d1877
commit
b2266ada26
120
static/app.js
120
static/app.js
@ -2594,6 +2594,126 @@ var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// global Stocks validation
|
||||||
|
|
||||||
|
function globalstockValidate() {
|
||||||
|
|
||||||
|
let x = document.getElementById("globalstocks_symbol").value;
|
||||||
|
let portfolioCheckbox = document.getElementById("globalstocks_portfolio");
|
||||||
|
let sharesText = document.getElementById("globalstocks_port_shares").value;
|
||||||
|
let averageCost = document.getElementById("globalstocks_port_cost").value;
|
||||||
|
let dateText = document.getElementById("globalstocks_port_date").value;
|
||||||
|
|
||||||
|
let text;
|
||||||
|
let text2;
|
||||||
|
if (x.toUpperCase() != x) {
|
||||||
|
document.getElementById('demo10').style.display = "block";
|
||||||
|
text = "Stock symbol must be uppercase";
|
||||||
|
document.getElementById("globalstocks_symbol").value = '';
|
||||||
|
// createLi = false;
|
||||||
|
}
|
||||||
|
else if (x === '') {
|
||||||
|
document.getElementById('demo10').style.display = "block";
|
||||||
|
text = "No blanks"
|
||||||
|
// createLi = false;
|
||||||
|
}
|
||||||
|
else if (x.includes(' ')) {
|
||||||
|
text = "No spaces";
|
||||||
|
document.getElementById('demo10').style.display = "block";
|
||||||
|
document.getElementById("globalstocks_symbol").value = '';
|
||||||
|
// createLi = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text = "Input OK";
|
||||||
|
document.getElementById('demo10').style.display = "none";
|
||||||
|
//PORTFOLIO VALIDATION HERE
|
||||||
|
if (portfolioCheckbox.checked) {
|
||||||
|
if ((sharesText === ' ') || (averageCost === ' ') || (dateText === ' ')) {
|
||||||
|
text2 = "No spaces";
|
||||||
|
document.getElementById('demo-portfolio-globalstocks').style.display = "block";
|
||||||
|
document.getElementById("globalstocks_port_shares").value = '';
|
||||||
|
document.getElementById("globalstocks_port_cost").value = '';
|
||||||
|
document.getElementById("globalstocks_port_date").value = '';
|
||||||
|
document.getElementById("globalstocks_symbol").value = '';
|
||||||
|
}
|
||||||
|
else if ((isNaN(sharesText))|| (isNaN(averageCost))) {
|
||||||
|
text2 = "No text characters, only numbers";
|
||||||
|
document.getElementById('demo-portfolio-globalstocks').style.display = "block";
|
||||||
|
document.getElementById("globalstocks_port_shares").value = '';
|
||||||
|
document.getElementById("globalstocks_port_cost").value = '';
|
||||||
|
document.getElementById("globalstocks_port_date").value = '';
|
||||||
|
document.getElementById("globalstocks_symbol").value = '';
|
||||||
|
}
|
||||||
|
else if ((!dateText.includes('-')) && (dateText !== '')) {
|
||||||
|
text2 = "Incorrect date format, it should be YYYY-MM-DD";
|
||||||
|
document.getElementById('demo-portfolio-globalstocks').style.display = "block";
|
||||||
|
document.getElementById("globalstocks_port_shares").value = '';
|
||||||
|
document.getElementById("globalstocks_port_cost").value = '';
|
||||||
|
document.getElementById("globalstocks_port_date").value = '';
|
||||||
|
document.getElementById("globalstocks_symbol").value = '';
|
||||||
|
}
|
||||||
|
else if (((sharesText !== '') || (averageCost !== '') || (dateText !== '')) && ((sharesText === '') || (averageCost === '') || (dateText === ''))) {
|
||||||
|
text2 = "Some fields are empty";
|
||||||
|
document.getElementById('demo-portfolio-globalstocks').style.display = "block";
|
||||||
|
document.getElementById("globalstocks_port_shares").value = '';
|
||||||
|
document.getElementById("globalstocks_port_cost").value = '';
|
||||||
|
document.getElementById("globalstocks_port_date").value = '';
|
||||||
|
document.getElementById("globalstocks_symbol").value = '';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text2 = "Input OK";
|
||||||
|
document.getElementById('demo-portfolio-globalstocks').style.display = "none";
|
||||||
|
createLi = true;
|
||||||
|
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
|
||||||
|
// addingItems();
|
||||||
|
let cost = document.getElementById('globalstocks_port_cost').value;
|
||||||
|
let shares = document.getElementById('globalstocks_port_shares').value;
|
||||||
|
let symbol = document.getElementById('globalstocks_symbol').value;
|
||||||
|
let days = document.getElementById('globalstocks_port_date').value;
|
||||||
|
|
||||||
|
let settings = {
|
||||||
|
shares:shares,
|
||||||
|
cost:cost,
|
||||||
|
symbol:symbol,
|
||||||
|
days:days,
|
||||||
|
};
|
||||||
|
console.log(JSON.stringify(settings));
|
||||||
|
|
||||||
|
setTimeout(
|
||||||
|
function() {
|
||||||
|
document.getElementById('globalstocks_symbol').value="";
|
||||||
|
document.getElementById("globalstocks_port_shares").value = '';
|
||||||
|
document.getElementById("globalstocks_port_cost").value = '';
|
||||||
|
document.getElementById("globalstocks_port_date").value = '';
|
||||||
|
document.getElementById("globalstocks_symbol").value = '';
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
if ((sharesText !== '') && (averageCost !== '') && (dateText !== '')) {
|
||||||
|
fetch("/saveGlobalPortfolioSettings", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(settings),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById("demo-portfolio-globalstocks").innerHTML = text2;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
createLi = true;
|
||||||
|
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
|
||||||
|
// addingItems();
|
||||||
|
setTimeout(
|
||||||
|
function() {
|
||||||
|
document.getElementById('globalstocks_symbol').value="";
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById("demo10").innerHTML = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Crypto validation
|
// Crypto validation
|
||||||
|
|
||||||
function cryptoValidate() {
|
function cryptoValidate() {
|
||||||
|
Loading…
Reference in New Issue
Block a user