Input onKeyPress Function Working Only After Clicking Away

Hi Yisrael,

Thanks for the pointers. I have added the console.log() statement and I do see all key presses including the Enter. Adding the logging also uncovered a new error that was not previously not showing in the console:

Uncaught (in promise)
{
code: “DS_VALIDATION_ERROR”,
message: “Some of the elements validation failed”,
name: “DatasetError”,
stack: “DatasetError: Some of the elements validation failed
at l (https://static.parastorage.com/services/dbsm-viewer-app/1.220.0/app.js:1:106793)
at Object.execute [as ADAPTER_API] (https://static.parastorage.com/services/dbsm-viewer-app/1.220.0/app.js:1:107322)
at https://static.parastorage.com/services/dbsm-viewer-app/1.220.0/app.js:6:61643
at f (https://static.parastorage.com/services/dbsm-viewer-app/1.220.0/app.js:1:96873)
at y (https://static.parastorage.com/services/dbsm-viewer-app/1.220.0/app.js:6:61614)
at Array.map () at https://static.parastorage.com/services/dbsm-viewer-app/1.220.0/app.js:6:62376”,
Symbol(error was handled): true
}

Interestingly, when I update my code to catch the error and print it, the error goes away, but the issue remains that my Enter is not triggering the save:

$w.onReady(function () {
$w(“#input8”).onKeyPress((event, $w) => {
console.log(event.key);
if (event.key === “Enter”) {
$w(“#dataset2”).save()
.then( () => {
$w(“#text37”).show(“FadeIn”);
})
.catch( (err) => {
console.log(err);
});
}
});
});

(No output displayed as a result of the catch and logging)

The nature of my problem seems to have changed a little, as there seems to be some underlying dataset error that may be the root cause. However, given the simplicity of my code and form set-up I am at a loss for what the issue could be. To quickly review my additional set up:

  • My database has a single “text” type field (called “email”)
  • My text input has “email” as its type. (I also tried “text” and get the same issue where “Enter” does not work)
  • My text input requires that the field is populated
  • My text input has no pattern validation
  • My text input is connected to my dataset, with the “value connects to” correctly mapped to the column in my database (“email (Text)”)
  • My dataset is in “Write-only” mode

I added the code to the onReady() statement because the WIX API documentation seemed to indicate it is best practice. There is a note regarding the save function that the dataset may not be ready until after the page is fully loaded. (wix-dataset - Velo API Reference - Wix.com).