From f3f9462c6ae1a55523a666dbeea8482a21b62411 Mon Sep 17 00:00:00 2001 From: Ratnadeep Rajendra Kharade <92khra1mst@hft-stuttgart.de> Date: Wed, 21 Oct 2020 17:26:47 +0200 Subject: [PATCH] allowed calculation once the form is valid --- public/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/public/index.js b/public/index.js index 33efa32..bbcdffa 100644 --- a/public/index.js +++ b/public/index.js @@ -43,12 +43,13 @@ function setCharacterLength(characters) { } function calculateReadingTime() { - let isFormValid = validateForm(); - let x = document.getElementById('calculate-time-element'); - x.style.display = "block"; + if (isFormValid()) { + let x = document.getElementById('calculate-time-element'); + x.style.display = "block"; + } } -function validateForm() { +function isFormValid() { let invalidFields = 0; if (inputObj.textChoice === 'manual' && inputObj.text === '') { invalidFields++; @@ -77,7 +78,9 @@ function validateForm() { } else { document.getElementById('readerCategory-validation').style.display = 'none'; } - + + return invalidFields < 1 + } function showFeedbackForm() { -- GitLab