Alert using CE - onAction event not firing

Hi. I’ve implemented the Alert by Salman.

https://www.wix.com/velo/forum/tips-tutorials-examples/build-an-alert-component-using-custom-elements

I can get the alerts to function well, and it’s a good alert app. Now I can’t get the onAction to fire on my page js.

export function button4_click ( event ) {
let alertPrivacy = {
message : “We Use cookies to store information! Accept our privacy policy!” ,
autoClose : false ,
closeLabel : “Accept” ,
onAction : handleAction ,
};
$w ( “#cealerts” ). setAttribute ( “newalert” , JSON . stringify ( alertPrivacy ));
}

function handleAction ( e ) {
/*
e => {
reason : reason, // action | timeout
message: message, // your message
id: id
}
*/
// save your cookie :slight_smile:
console . log ( “yes” )
}
Here is a very simple example of an alert, with a button to accept. When I click the button, I do not receive the console message.

If I remove the handleAction() from the main page and run the page in live mode, a console error lets me know the function doesn’t exist, so it’s def. expecting it.

Here is the github link with the exact code example.

Any help ?

Hi paul.

When using a function u should always use () behind it.

So when you have :
onAction : handleAction

it should be

onAction : handleAction()

Kind regards,
Kristof.

This is the example from the githib. If I put in the (), then the function just executes when I clock button4.