Panel field javascript click does not work after save

So far there’s no complete or loaded event, but we can easily add this. The correct way to handle this so far is to create a jquery field plugin.

A jQuery field plugin is easy to create. Here’s a boilerplate: https://gist.github.com/bastianallgeier/9398bbd72dcc782827a8

So this will take care of cleanly initiating the js code for every field instance and get the events right.

In your PHP field class, you can then activate the jQuery plugin for the field like this:

  public function element() {

    $element = parent::element();
    $element->data('field', 'myfield');

    return $element;

  }

What this does is to add a data-field attribute to the wrapping div around the field. The panel will automatically look for a jQuery plugin with the same name and initialize all events on every load.

In your jQuery plugin you can then do all the normal stuff you would do on document ready.

The field variable already from the boilerplate has the scope of the field div. So you can do finds within the div like this:

field.find('.calle-table td').on('click', function() {

});

I hope this helps.

5 Likes