Change Alert via JS

Hi all,

I have a button and alert widget. When I press the button I would like to change the alert type and description. I've create a JS query:
alert1.description = "my description";
alert1.type = "error";

This query trigger on button pressed, but the alert widget doesn't change. What am I missing here?

Thanks a lot!

Hello,

All components' properties are read-only when accessing within JS, hence you can't change it in JS.
image

You can use Temporary State to store your data:

image

apply to the alert component...make sure you toggle "fx" to allow dynamic value.

image

Then button to trigger a JS logic to update the temporary state value.

alerts

Test app
alert.json (5.8 KB)

2 Likes

Perfect! Thank you!

1 Like