I have a text box [$w(“#textBox3”)] that the user can enter text into and when pressing “Enter” the text box should be cleared and the entered text should be pushed in $w(“#text1”). This all works fine however even though the text box is cleared if the user presses “Enter” again it pushes the same value into $w(“#text1”). This does not happen if done with a button.
Note: There are extra lines of code to stop empty values being sent.
Here is the code:
let Input1;
export function textBox3_keyPress(event) {
//Add your code for this event here:
if(event.key === "Enter"){
event.key = "";
event = "";
Input1 = $w("#textBox3").value
$w("#textBox3").value = "";
let i;
for (i = 0; i < Input1.length; i++) {
if (Input1[i] === '\n' || Input1[i] === '\r') {
console.log("Enter")
} else {
if (Input1[i] === ' ') {
console.log("Space")
} else {
console.log("Text")
i = Input1.length;
console.log("Input: ", Input1)
$w("#text1").text = $w("#text1").text + " " + Input1;
Input1 = "";
$w("#textBox3").value = "";
} // End of Input[i] if Space
} // End of Input[i] if Enter
} // End of for loop
} // End of if
$w("#textBox3").value = "";
Input1 = "";
}
Does anyone know how to make it only send the value on the first press of “Enter” and not the second?