Form submission on value input

Hi, I have a Wix Form on my page with one input field (Autocomplete Address Field) and a Submit button. What I want is to submit the form as soon as user inputs (choose from a dropdown) their address ie enters a value into the field, without a need to click the submit button.

I have tried many options already and nothing seems to work.

I started from a simple:

$w.onReady(function () {
$w(“#addressInput1”).onChange(() => {
const selectedAddress = $w(“#addressInput1”).value;
if (selectedAddress && selectedAddress.length > 0) {
$w(“#form2”).submit();
}
});
});

Then tried to use $w(“#submitButton1”).click(); and $w(“#submitButton1”).fireEvent(“onClick”);

I am still struggling but can’t find a solution.

Any help would be greatly appreciated.

Hi, d1nk !!

By the way, are you using the newer version (v2) of Wix Forms, or the older one? I’m guessing you’re probably using the older version. :upside_down_face:

The older one, as the newer doesn’t have an autocomplete address field.

I see, :innocent: I don’t clearly remember how to implement it with the old form, but I believe you don’t need to use something like .submit(). You can probably just use .save() on the dataset to save the form data to the collection. So, the first thing you need to do is create a dataset and link it to the collection you’re using for the form. After that, you should be able to make it work using code like the example below. :upside_down_face:

$w("#addressInput1").onChange(() => {

  const selectedAddress = $w("#addressInput1").value;

  if (selectedAddress && selectedAddress.length > 0) {

    $w("#formDataset1").setFieldValues({
      address: selectedAddress,
    });

    $w("#formDataset1")
      .save()
      .then(() => {
        console.log("done!");
      })
      .catch((err) => {
        console.log(err);
      });

  }
  
});

Well, personally, I think that from a user interface perspective, some users might find it problematic if the data is submitted automatically without any notice. So even if you want to submit it automatically, it’s probably better to show some kind of popup, like a lightbox, beforehand. :thinking:

1 Like

Thank you so much for this, I will try to implement it and then will come back here :slight_smile:

1 Like

Not sure if you’ve had the opportunity to user the new Forms recently, but the auto-complete address field has been out for some time :slight_smile:

Multi-line address> Settings on the field> Advanced> Enable autocomplete

1 Like

wow that’s a valuable addition, thank you. What do I loose using old forms vs new?