Panel trigger built in field js from generated html

When for example extending the url field, the javascript is aware of that element. When adding new html with javascript is not aware of the new html because it did not exist when the javascript file was loaded.

The html generating function

This function is similar to the one I have for generating the html, in another field.

field.find('.a-button').click(function() {
  // Adding the element with javascript
  // Possible to trigger the js again?
});

Is it possible to somehow trigger to load of the url field javascript again? I’ve tried trigger and some other fancy ideas but I did not succeed. Is the only way to replicate the javascript file in an extended field?

I don’t think I need a copy/paste solution. Hints in a direction would be great as well.

Here is the url.js. I took the url field as an example because it’s very small but there are many other fields that rely on javascript as well. Trigger the $.fn.urlfield at a later point of time is what I want to do, after the html is changed.

You would need to remove the data from the element. Then you are able to reinit the script. You probably need to remove all previously set event handlers too. Otherwise you would end up with two events called on one click.

$('[data-field="urlfield"]')
  .removeData('urlfield')
  .off('click')
  .urlfield();

Not sure right now if there are other click events on the object. If so you need to be carefull which events you delete.

Great! :smiley: That worked perfectly. I did not even need to change anything with it. I will use it carefully. Thanks!