Developer forum

Forum » Swift » Callback after PageUpdater.Update

Callback after PageUpdater.Update

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Is there a way I can run custom code when PageUpdater.Update is done? I need to reload the page after the user has selected a different country code (the cart checks if items are valid for a given country). When I try code like this (from AddressUser.cshtml):

useBillingAddress = function () {
  document.querySelectorAll("input[name^='EcomOrderDelivery']").forEach(function (field) {
    field.removeAttribute("disabled");
  });
  swift.PageUpdater.Update(document.querySelector("#ordersubmit"));
  location.reload()
};

it fails in Firefox because somehow the GET request from location.reload() cancels the post from PageUpdater.Update:

Currently, I use setTimeout and wait for half a second, but I rather execute the code immediate when PageUpdater.Update is done, like so:

swift.PageUpdater.Update(document.querySelector("#ordersubmit"), location.reload());

but that doesn't work currently. Is there a callback option on Update I can use? Or an alternative?

Imar

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

You can use the events from Swift: https://doc.dynamicweb.com/swift/customization/guides/extending-swift-javascript-modules

document.addEventListener("updated.swift.pageupdater", ()=>alert())

 

You must be logged in to post in the forum