1
0
Fork 0

Update app.js - Fixed back button bug and disallow input during message

master
stweedo 2023-06-03 12:42:40 -05:00 committed by GitHub
parent feafb53854
commit 79c98c2eac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -43,6 +43,7 @@ let calculatedVariable;
let selectedVariable; let selectedVariable;
let variableValues = {}; let variableValues = {};
let inputStr = ""; let inputStr = "";
let invalidInput = false;
// Function references // Function references
let handleEnter; let handleEnter;
@ -108,6 +109,9 @@ function setValue(newStr) {
// Function to handle the press of a button and append its value to the current input // Function to handle the press of a button and append its value to the current input
function handleButtonPress(value) { function handleButtonPress(value) {
if (invalidInput) {
return; // Don't allow input if an invalid input error message is displayed
}
inputStr = value === 'C' ? '' : inputStr + value; inputStr = value === 'C' ? '' : inputStr + value;
setValue(inputStr); setValue(inputStr);
} }
@ -176,7 +180,10 @@ function calculateValue(calculatedVariable, variableValues) {
clearScreen(); clearScreen();
let variableSelectionMenu = { let variableSelectionMenu = {
'': { 'title': 'Select Variable' }, '': { 'title': 'Select Variable' },
'< Back': () => E.showMenu(mainMenu) '< Back': () => {
E.showMenu(mainMenu);
variableValues = {};
}
}; };
let variables = Object.keys(UNITS); let variables = Object.keys(UNITS);
let remainingVariables = variables.filter(v => v !== calculatedVariable && !variableValues[v]); let remainingVariables = variables.filter(v => v !== calculatedVariable && !variableValues[v]);
@ -208,8 +215,12 @@ function calculateValue(calculatedVariable, variableValues) {
if (inputStr === "" || isNaN(inputStr) || (inputStr.match(/\./g) || []).length > 1) { if (inputStr === "" || isNaN(inputStr) || (inputStr.match(/\./g) || []).length > 1) {
// Show error message // Show error message
setValue("Invalid Input"); setValue("Invalid Input");
invalidInput = true; // Prevent further input
// Clear error message after 2 seconds // Clear error message after 2 seconds
setTimeout(() => setValue(''), 2000); setTimeout(() => {
setValue('');
invalidInput = false; // Allow input again
}, 2000);
return; return;
} }