Hi Yisrael,
I agree with your assessment. And as I discovered, the Uncaught (in promise) error is related to the required flag on the input box. But also as I pointed out, removing it causes a different breakage.
I have updated my input box to not be “required”, and updated my code to set the value before saving (in the onReady() function of the site). This results in the desired behavior. My code now looks like:
$w.onReady(function () {
$w(“#input8”).onKeyPress((event, $w) => {
if (event.key === “Enter”) {
$w(“#dataset2”).setFieldValue(“email”, $w(“#input8”).value);
$w(“#dataset2”).save()
.then( () => {
$w(“#text37”).show(“FadeIn”);
});
}
});
});
For future reference to others or WIX developers, this code works around two issues that I believe are bugs:
-
A form input field with the “required” setting enabled will not validate whether it has input (and therefore meets the “required” state) until after a user has clicked off of the input field.
-
On a single input form that does not have a submit button (and relies on a key press to submit the data from the input), the dataset will not capture the information from the input field unless it is marked as “required” in the input field settings. This may also apply more generally to forms with multiple inputs, or forms with submit buttons, but I did not test the behaviors for these scenarios.