Why do I need to use setTimeout to refresh dataset after save?

I have a repeater that displays a list of businesses. The repeater is connected to a ReadOnly dataset. The user can click an edit button on the repeater to display a form for editing. The form fields are connected to a Read&Write dataset. Both datasets are for the same collection. When the user clicks submit, the data saves correctly, but I have to use setTimeout to get the repeater to refresh.

Repeater connected to datasetList (this is ReadOnly from ‘businesses’ collection)

Form connected to datasetForm (this is Read&Write from ‘businesses’ collection)

//This works
export async function submit_click(event) {
    $w("#businessFormContainer").hide()
    await $w("#datasetForm").save()
    setTimeout(()=>{$w("#datasetList").refresh()},100)
}
//This does not work
export async function submit_click(event) {
    $w("#businessFormContainer").hide()
    await $w("#datasetForm").save()
    $w("#datasetList").refresh()
}
//This does not work
export function submit_click(event) {
    $w("#businessFormContainer").hide()
    $w("#datasetForm")
      .save()
      .then(() =>              
             $w("#datasetList").refresh()
       )
}

Why do I need to use setTimeout? I shouldn’t be fetching the data for datasetList until the update is finished? I would love to find a way to do this properly with promises instead of this work around.

  1. First of all, change your coding style and forget about the usage of export functions on your frontend.

Instead, —> code inside the → [Page.onReady-Block] !!!

  1. Second, i do not see at any part of your code that you are waiting for DATASET to be ready first before working with it! And here we go gain → your coding-style is not the best idea to work on wix-codes!!!

We are waiting until our wix-page gets ready first !!!

$w.onReady(()=>{
	console.log("Yeaha, my page is ready, my code can start!!!");
	
	console.log("Oh sh..., i forgot to wait for my DATASET!!!");
});
console.log('let's try again');

$w.onReady(()=>{console.log("Yeaha, my PAGE is ready...");
  $w.('#myDatasetIDhere').onReady(()=>{
	  console.log("Yeaha, my DATASET is ready...");
	
	  console.log("This time i didn't forget aboout my DATASET");
	  console.log('Let's start to work with my dataset!!!');
  });
});

You have the saving process, which will need time to save data into your database, which is connected through your dataset.

  1. and third…
$w.onReady( () => {
  $w("#myDataset").onReady(()=> {
    $w("#myDataset").save()
      .then((item)=> {console.log("Item: ", item);
        let fieldValue = item.fieldName;
        console.log("Field-Value: ", fieldValue);
      })
      .catch((err)=> {let errMsg = err;});
  });
});

Still something missing? ? ?
Of course! → already setted-up the field-Values?

$w("#myDataset").setFieldValues( {
  "title":  "New Title",
  "name":   "New Name"
});

Ohhhhhh, but wait, why you can save data without setting up the field-values first?
Ohhhhhh, (you hear the second ohhhhhh) ??? → you connected your dataset inside the PROPERTY-PANEL → and connected the Submission-Button???

Ohhhh! Always the same! :rofl:

Stop that shitty codings! This will end in —> NOWHERE !!! (ohh, that is for everybody, who read this post xDDDD).

And now take a look onto → hooks <— since you have used the connections inside property-panel…

Number-1:

$w("#myDataset").onBeforeSave( () => {
  console.log("Canceling save");
  return false;
} );

Number-2:

$w("#myDataset").onAfterSave( () => {
  console.log("After save")
});

And now first do some brainstorming!
-What is my exact setup?
-Did i use a dataset?
-What kind of dataset did i use? (dynamic or non-dynamic)?
-Did i use connections inside PROPETY-PANEL ?
-Do i really want to continue the EXPORT-FUNCTIONS-WAY?
-Is my Submit-Button (save-button) connected to my dataset?
-Or do i want to code this part?
-How, where, when and why to use NUMBER-1 and NUMBER-2 ???

What the hell !!! :rofl: → confusing shit?

Answer: —> NOPE !!! Just a standard process.

Try again!