Reload js in builder after element rerenders?

Hi bricks-developers,

I’ve a custom element that depends on javascript. Everything works as expected when initially loaded in the builder. But when I do make a change in a control-field the element get’s rerendered on the canvas but the js-code is not re-triggered. I can see that the elements render function in php is called again but the js-code is not called again.
For the element to be rendered it’s required that the js-code reruns. How can I achieve that? On the frontend everything works fine and as expected, it’s just a builder-issue.

Br

Tobias

Hi Tobias,

Inside your custom element PHP class, make sure to define the $scripts variable, and add the name(s) of the JS function(s) you want to run on it as an array.

Example:
public $scripts = ['bricksCounter'];

Replace the bricksCounter JS function name with your own :slight_smile:

This is also mentioned in our developer docs:

1 Like

Hi Thomas,

thank you so much for your reply! Works like a charme now! I have had read the documentation but I didn’t know that the term ‘script’ refers to a function. I thought it referred to a script tag or filename. I had tried that but of course without success.

Br and thanks!

Tobias

1 Like