Delaying a Refresh Dataset

Hello,
this should be really easy but I just can’t figure out how to do it.

I’m making a staff page where you put in some information in a form and the dataset shown in the bottom refreshes and shows what you’ve submitted.

so what I’m trying to do is.

when my staff members click “Submit” the button should upload the content (which

it does) and after 500 ms it should refresh my dataset.

I have tried this

const myTimeout = setTimeout ( button17_click ( 1000 )

export function button17_click ( event ) {
// Refresh to load more data into dataset
$w ( ‘#dataset2’ ). refresh ();
}

but i’m not sure what I’m doing wrong

can anyone help :slight_smile:

here’s a picture of the design for now

Hello. Have you tried running a query to whatever is populating that dataset instead of using refresh? My assumption here is that the submit is updating your collection and what you need to do is query the collection again to populate the repeater.

what happens is when they upload data to the dataset, the repeater underneath dosen’t update, unless they press my update button, what I want is just when they hit submit, the dataset refreshed a few seconds afterwards so my client can see the update

@mikkelhmogensen A better approach would be to not connect the button to the dataset submit and handle it all in code. So what you would do:

  1. Remove the connection between the submit button and the dataset submit property.

  2. Add the following code to the $w.onReady() section:
    $w (“#NameOfTheSubmitButton”). onClick (( event ) => {
    $w ( ‘#dataset2’ ).save()
    .then ((response) => {
    // data saved!
    $w ( ‘#dataset2’ ).refresh()
    })
    .catch ((error) => {
    // Error saving data
    console.log(error);
    })
    });

When the submit button is clicked, this code will save the dataset record and then call the refresh after the save has successfully completed. This way you don’t need to mess around with time delays or multiple events.

@robmich Great suggestion. Thanks for weighing in!

@robmich Thanks man! I’ll have a look :slight_smile:

@mikkelhmogensen Its Working as intended! Thank you very much!

@robmich It’s working as intended!! Thank you very much!