From 436e261fa72a48676942e9dd0ec2a4ad006a6900 Mon Sep 17 00:00:00 2001 From: Severin Kaderli Date: Wed, 23 Nov 2022 16:55:41 +0100 Subject: [PATCH] Validate input field Signed-off-by: Severin Kaderli --- src/website/index.html | 11 ++++++++++- src/website/scripts/Main.js | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/website/index.html b/src/website/index.html index b36d213..45a1ae4 100644 --- a/src/website/index.html +++ b/src/website/index.html @@ -10,7 +10,16 @@
- + +

diff --git a/src/website/scripts/Main.js b/src/website/scripts/Main.js index 41e173a..ee6180f 100644 --- a/src/website/scripts/Main.js +++ b/src/website/scripts/Main.js @@ -51,6 +51,23 @@ function stopCalibration() { } function startSending() { + textInput.setCustomValidity(""); + // Validate the input + if (!textInput.checkValidity()) { + + console.log(textInput.validity); + if (textInput.validity.valueMissing) { + textInput.setCustomValidity("Please enter between 1 and 16 characters."); + } + + if (textInput.validity.patternMismatch) { + textInput.setCustomValidity("Please only enter valid ASCII characters."); + } + + textInput.reportValidity(); + return; + } + startSendingButton.classList.add(hideClass); stopSendingButton.classList.remove(hideClass); Utility.setMessage(`Sending message: ${textInput.value}`);