Skip to content

Commit

Permalink
fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTrofimov committed Apr 18, 2020
1 parent 1ee72c7 commit 11336d1
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 275 deletions.
8 changes: 8 additions & 0 deletions css/analys-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@
-ms-flex-preferred-size: 0;
flex-basis: 0;

}

#cab-text {
font-style: normal;
font-weight: 300;
font-size: 30px;
line-height: 42px;
padding-top: 10px;
}
9 changes: 9 additions & 0 deletions css/cab-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
font-size: 22px;
}

.user-data-first {
margin: auto;
padding-right: 10px;
font-size: 22px;
width: 400px;
text-align: center;
}

.row1, .row4, .row5, .row6, .row7 {
display: flex;
}
Expand Down Expand Up @@ -159,6 +167,7 @@
background-color: #f1f1f1
}

/* Show the dropdown menu on hover */
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
Expand Down
77 changes: 71 additions & 6 deletions js/analys.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
// получили данные
var smoking, smoking_exp, weight, height, alco, sistol, diast, temperature, pulse, sugar, holest, sleep, stress, phis;
var smoking, smoking_exp, weight, height, input_alco, alco, sistol, diast, temperature, pulse, sugar, holest, sleep, stress, phis;
if (window.location.pathname === '/med-project/templates/analyse.html') {
const resultBtn = document.getElementById('result-button');
resultBtn.addEventListener('click', function () {

// getting data
smoking = document.getElementById('smoking').value.toLowerCase();
smoking = document.getElementById('smoking').value.toLowerCase() === "да";
smoking_exp = document.getElementById('smoking-exp').value;
weight = document.getElementById('weight').value;
height = document.getElementById('height').value;
alco = document.getElementById('alco').value.toLowerCase();
input_alco = document.getElementById('alco').value.toLowerCase();

switch (input_alco) {
case "полный отказ": alco = 1;
case "несколько раз в год": alco = 2;
case "каждый месяц": alco = 3;
case "каждую неделю": alco = 4;
case "ежедневно": alco = 5;
}

sistol = document.getElementById('sistol-presure').value;
diast = document.getElementById('diast-presure').value;
temperature = document.getElementById('temperature').value;
Expand All @@ -36,7 +45,8 @@ if (window.location.pathname === '/med-project/templates/analyse.html') {
localStorage.setItem("stress", stress);
localStorage.setItem("phis", phis);

console.log(smoking, smoking_exp, weight, height, alco, sistol, diast, temperature, pulse, sugar, holest, sleep, stress, phis);
// logs
// console.log(smoking, smoking_exp, weight, height, alco, sistol, diast, temperature, pulse, sugar, holest, sleep, stress, phis);

window.location.href = '/med-project/templates/results/result.html';
});
Expand All @@ -47,10 +57,65 @@ if (window.location.pathname === '/med-project/templates/analyse.html') {
// const xhr = new XMLHttpRequest();
// xhr.open('POST', 'ссылка на сервер');

function validateDig(form, reg, max, min) {
if (arguments.length === 3) {
var min = 0;
}
form.addEventListener('blur', function (e) {
if (reg.test(e.target.value) && e.target.value > min && e.target.value < max) {
e.target.style.border = '2px solid lightgreen';
} else {
e.target.style.border = '2px solid red';
}
});
}

function validateStr(form, reg) {
form.addEventListener('blur', function (e) {
if (reg.test(e.target.value)) {
e.target.style.border = '2px solid lightgreen';
} else {
e.target.style.border = '2px solid red';
}
});
}



// validating forms
// nums
smoking_exp_in = document.getElementById('smoking-exp');
weight_in = document.getElementById('weight');
height_in = document.getElementById('height');
sistol_in = document.getElementById('sistol-presure');
diast_in = document.getElementById('diast-presure');
temperature_in = document.getElementById('temperature');
pulse_in = document.getElementById('pulse');
sugar_in = document.getElementById('sugar');
holest_in = document.getElementById('holest');
sleep_in = document.getElementById('sleep');
stress_in = document.getElementById('stress');
phis_in = document.getElementById('phis');

// strings
smoking_in = document.getElementById('smoking');
input_alco_in = document.getElementById('alco');

// validating nums
validateDig(smoking_exp_in, /\d+/, 50);
validateDig(weight_in, /\d+/, 150);
validateDig(height_in, /\d+/, 250, 100);
validateDig(sistol_in, /\d+/, 200, 30);
validateDig(diast_in, /\d+/, 200, 30);
validateDig(temperature_in, /\d\d\.\d/, 42.0, 34.0);
validateDig(pulse_in, /\d+/, 20, 250);
validateDig(sugar_in, /\d\.\d/, 20);
validateDig(holest_in, /\d\.\d\d/, 10.00);
validateDig(sleep_in, /\d+/, 24);
validateDig(stress_in, /\d+/, 11, -1);
validateDig(phis_in, /\d+/, 11, -1);

// validating strings
validateStr(input_alco_in, /Полный\sотказ|Несколько\sраз\sв\sгод|Кажный\sмесяц|Каждую\sнеделю|Ежедневно/);
validateStr(smoking_in, /Да|Нет/);



Expand Down
46 changes: 45 additions & 1 deletion js/cab.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,48 @@ function makeStraight() {
}
}

makeStraight();
makeStraight();

// validating

function addClass(el, className) {
if (!el.classList.contains(className)) {
el.classList.add(className);
}
}

function rmClass(el, className) {
el.classList.remove(className);
}

var height = document.getElementById('height-cab');
var weight = document.getElementById('weight-cab');
var age = document.getElementById('age-cab');
var gender = document.getElementById('gender-cab');
var smoking = document.getElementById('smoking-cab')

function validateDig(form, reg, max) {
form.addEventListener('blur', function (e) {
if (reg.test(e.target.value) && e.target.value > 0 && e.target.value < max) {
e.target.style.border = '2px solid lightgreen';
} else {
e.target.style.border = '2px solid red';
}
});
}

function validateStr(form, reg) {
form.addEventListener('blur', function (e) {
if (reg.test(e.target.value)) {
e.target.style.border = '2px solid lightgreen';
} else {
e.target.style.border = '2px solid red';
}
});
}

validateDig(height, /\d+/, 250);
validateDig(weight, /\d+/, 150);
validateDig(age, /\d+/, 100);
validateStr(gender, /[м,ж]/i);
validateStr(smoking, /да|нет/i);
Loading

0 comments on commit 11336d1

Please sign in to comment.