Form with automatic input not posting to database

I am having a problem that has me stumped. This simple form is not acting as it should. I am trying to add pictures to a database. I have some real-estate properties and each property can have multiple pictures, so I keep the pictures in a separate database.

Below I have written some code… This code should simply grab the property ID from the property chosen in the dropdown menu. It appears to work perfectly. The second I select a property, the ID is displayed in input2.

import wixData from ‘wix-data’;

$w.onReady(function() {

});

export function dropdown1_change(event, $w) {
let dropdownSelPropName = $w(“#dropdown1”).value;
wixData.query(“Properties”)
.eq(“propertyName”, dropdownSelPropName)
.find()
.then((results) => {
let currentID = results.items[0].propKey;
$w(‘#input2’).value = currentID;

	}); 

}

From this point all looks well. I add a name to the Image, choose the file, and hit submit.

For some reason this is the result in the database

The property ID is the last field and it will not populate if the id was generated with the code.

If I manually enter in the property ID it works fine, but for some reason having it coded in there it does not work!

Any suggestions??

Hi Jason,

few things to check

  1. Is #input2 correctly bound to appropriate property of the Dataset?
  2. Are there any errors popping up in console when you click Submit?

Also, what is the type of the property?

Thank you for the response.

The #input2 is appropriately connected to the Dataset. When I manually enter information into #input2 it works and populates the database.

There are no erros in consol.

The propertyID is a text value.

It is very strange as when I click submit it acts as if I have left the #input2 completely blank

In that case, instead of

$w('#input2').value = currentID;

try

$('#yourDatasetId').setFieldValue('propertyName', currentID)

Let me know!

1 Like

Works Perfectly!!! Thank you so much!