inputText value is not updating

Im trying to update a field when a user press ‘Enter’ in the input field. I wrote this:

$w(“#userInput”).value = “placeholder value”;
$w(“#userInput”).onKeyPress((event) => {
if (event.key === “Enter”) {
console.log(event.context);
console.log($w(“#userInput”).value);
}
});

the log to the console when I press ‘Enter’ is “placeholder value” (i know there is an attribute for a placeholder), if I dont set the value, the console logs an empty string.

i would expect it to print the string that i put in the input field.

Any ideas why this is happening and how to make this work?

Hello.

I have checked your code and could see that it works just fine. To print your input in the console just comment out the placeholder line as shown below:

$w.onReady(function () {
//$w("#userInput").value = "placeholder value";
$w("#userInput").onKeyPress((event) => {
if (event.key === "Enter") {
console.log(event.context);
console.log($w("#userInput").value);
}
});
});

Good luck!

This works in a regular button and input field, but my problem seems to be when its inside a repeater object. When I put the same objects in a repeater container the value is always empty or the previous value. Any ideas why?