How to Overwrite (update) eventlisteners?

In Wix I think we can’t update or overwrite our eventlisteners like onClick what can I do about this issue?

Example:

$w("#Button123").onClick((event) => { runFunction() })
$w("#Button123").onClick((event) => { runFunction() })

If I write this code runFunction will be fired 2x times. This is the issue that I’m having. Also even if I have different functions like:

$w("#Button123").onClick((event) => { runFunction() })
$w("#Button123").onClick((event) => { runFunctionTwo() })

Again both will fired. Another example:

function setup() {
    $w("#Button123").onClick((event) => {
        console.log(123)
    })
}

setup()

function updateItems() {
    setup()
}

updateItems()

In this exmaple I would see 2x console.log(123) even if I click once. Because updateItems function created the same eventlistener once again!

This is the issue I hope I was able to let you understand what I meant. So?

How can I overwrite or basically update my eventlistener and not create new one each time?

Wix must make an update about this and let eventlisteners overwrite automatically. How it should be example:

$w("#Button123").onClick((event) => { runFunction() })
$w("#Button123").onClick((event) => { runFunctionTwo() })

Only runFunctionTwo will be executed. Each time we create new eventListener it should overwrite old one.

-Maybe Wix can create a new selector like $o and we can use it when we want to overwrite.

(I’m not a master so maybe I’m thinking false but this is my idea because I’m having problem with this)

I fixed it but how?

I had a problem about this and I fixed it using Repeaters in my case it worked for me but for many other cases it might not work so please Wix make an update and let us be able to do one of following:

  1. Remove event listeners

  2. Overwrite/update eventlisteners

  3. New selector to overwrite or update eventlisteners like $u/$e anything.

Or any other solution for this!

Hi, I think this is actually possible if you define your event listener in the following way:

let runfunction = function(){code to run}
$w("#Button123").onClick(event=>{runFunction()})

Then to change it you can redefine the function like so

runfunction = function(){other code to run}

You should be able to add variables too, like so

let runfunction = function(event){code to run}
$w("#Button123").onClick(event=>{runFunction(event)})