save() clears page text inputs

I have a page with many elements linked to a collection via a dataset. The issue I am currently experiencing is that when I call save(), every single text input element on the page is cleared of user input. What is causing this, and how do I stop it from happening?

Here is the code that sets field values and saves the data:

function claimButton() {
  wixWindow.openLightbox('CLAIM KICKSTARTER REWARD').then(data => {
    $w('#dKickstarter').setFieldValue('firstName', data.firstName);
    $w('#dKickstarter').setFieldValue('lastName', data.lastName);
    $w('#dKickstarter').setFieldValue('emailAddress', data.emailAddress);
    $w('#dKickstarter').setFieldValue('orderStatus', 'New');
    
    for (let i = 0 ; i < dynamicElementCount ; i++) {
      $w('#dKickstarter').setFieldValue(`text${i+1}`, textInputElementIds[i].value);
    }
    
    $w('#dKickstarter').save();
  });
}

Note that the text input field values are being set in the ‘for’ loop.

EDIT

Code added.

1 Like

Wondering about this as well, perhaps save() doesn’t play well with write-only datasets?

I was having this SAME issue with the save function on my database. To make things worse my database was MASSIVE and I thought I would have to rebuild it from scratch. Fortunately that was not the case as wix automatically backs up database collections. YOu can easily restore a previous version. See: Restoring a Deleted Content Collection | Help Center | Wix.com

Now for the solution. There is actually two ways to do what you want. If you want to continue using the .save function you will need to pass in all the existing data in the collection field and then just update the value that you want. This can get quite cumbersome and does not account for any future database expansions. So instead I reccomend a wix package called Data helpers.

This package has a function called getAndUpdate that works exactly like you would expect the save function to work. You simply provide a collectionId, an itemId, and then pass a value that you would like to update. You can read all about it here: https://www.wix.com/velo/reference/velo-package-readmes/wix-data-helpers