Hi guys, I have two forms, each connected with a dataset:
-
Application form (dataset1 write only) where we have to pick a costumer with a dropdown (reference to customer collection)
-
In case the customer is not in the database yet, I have a second form New Customer (dataset2 write only).
Question: When I save the New Customer I also refresh the other dataset but, the dropdown is not refreshed and I can’t pick the new customer. Only if I am reloading the site, it is added. Is there a way to refresh the object? I am using the following code on the customer save button:
$w.onReady( function () {
//Neuer Kunde Speichern
$w(“#button6”).onClick(() => {
$w(“#dataset2”).save()
.then(() => {
if ($w(“#columnStrip1”).collapsed) {
$w(“#columnStrip1”).expand();
} else {
$w(“#columnStrip1”).collapse();
}
});
//wixLocation.to(“https://www.home4motion.com/neues-erstgespraech”)
})
$w("#dataset2").onAfterSave( () => {
$w("#dataset1").refresh()
$w("#dataset3").refresh()
console.log("datset 1 refrehed");
} );
Many thanks for your input!
If both datasets are set to write only, then how can either dataset read any new user input?
Hence why your dropdown only shows the new user input after the page is also refreshed and both the page and the datasets have reloaded with the new content in them.
A dataset can be in one of three modes, which are set in Dataset Settings panel in the Editor. The dataset’s mode cannot be changed programmatically.
if you want to refresh the page as a whole and stay on the same page, then simply set your wixLocation.to - wixLocation.to(wixLocation.url); //This reloads the same page
THX givemeawhisky for your quick answer!
I agree with you, but I don’t want to reload the site if possible - it’s not a very sexy solution.
With the dropdown list from dataset1, I am choosing the customer from dataset2 → I anyway can read and pick from write only → but I have the same issue if I change it to read and write though.
Why is it not updating the customers within the dropdown when I
- .save
- .refresh the dataset.
Is there any other coding solution?
@fzupan Try setting some temporary text element and change its text onAfterSave to see if the event listener is actually working. It might just be printing out in console without actually refreshing dataset3 (which I’m assuming is the one with read permissions the dropdown is connected to). If the text element doesn’t change, it’s definitely a bug for Wix to squash.
I think the only way to refresh the dropdown would be to set all its values again, so you would have to fetch the data using a query after save(if it doesn’t work, then you could use setInterval) and set the dropdown’s values that way.