Hi guys. First of all, LiveView is awesome. Thanks to everyone contributing.
I have a page with a filter (search and sort) and “load more” type pagination.
I’m using temporary_assigns
for the collection of items and phx-update="append"
for the pagination.
However, when filter form is changed, I want the collection items to be replaced instead of appended. When, for example, the sorting is changed, the collection of items should start from page 1.
So is it possible to alter the behaviour of phx-update conditionally? How can I utilize the functionalities of both append and replace in the same view/component?
I have tried hooking the form to empty the collection, but failed:
Hooks.Replace = {
beforeUpdate() {
const nodeEmptied = document.getElementById("to-be-replaced-elem");
while (nodeEmptied.firstChild) {
nodeEmptied.removeChild(nodeEmptied.firstChild);
}
}
}
Any help would be greatly appreciated.