Validation TextInput when Enter is hit

Hi everyone,

First of all, I am not very used to code, but I tried! Below you can see a Quiz I created. The right answer to this question is ‘la’.


I created this quiz with the code:

export function controleer2_click() {
$w(“#textInput3”).onCustomValidation( (value) => {
if(value === “la”) {
$w(“#volgendebutton2”).show();
$w(“#uiteg2”).show();
$w(“#line10”).hide();
$w(“#antwoordbutton2”).hide();
$w(“#nogeens2”).hide();
$w(“#textInput3”).disable();}
else {
$w(“#line10”).show();
$w(“#uiteg2”).show();
$w(“#nogeens2”).expand();
$w(“#antwoordbutton2”).expand();}
});


So it depends on their answer what they see and what they can do next. For example, they can go to the next question if the answer is right.

But the answer will only be ‘checked’ after they push the button ‘controleer’ (Dutch); I am wondering if I can validate their answer after they hit the Enter-key, when they filled in their answer, instead of having to click on the ‘controleer’-button.

Hi

Yes it is possible you can add event listener to the keyPress of the textInput component


and then on the event you can add the following code

if (event.code === 13){ 
	console.log('ENTER WAS PRESSED') 
} 


in javascript each key has a keycode and is allows you to know what key was pressed here is the full list

1 Like