processwire / processwire-issues

ProcessWire issue reports.
45 stars 2 forks source link

Error in inputfields.js addHeaderAction() #1976

Open Toutouwai opened 2 months ago

Toutouwai commented 2 months ago

Short description of the issue

I'm adding an inputfield header action:

$inputfield->addHeaderAction([
    'icon' => 'question-circle',
    'event' => 'testing',
]);

Clicking on the header action icon causes this JS error in the browser console:

2024-09-20_210214

I think line 1333 is perhaps supposed to be:

if(settings.event) $icon.trigger(settings.event, [ $icon ]);

Also, I'd like to be able to have both an href and an event for the same header action, so can the logic please be updated so that the event is triggered even if the href option is set? And the callback option too as I can imagine using that together with an href.

Lastly, please don't use return false in event listeners as this prevents other JS code from listening to the same event. Discussed here: https://github.com/processwire/processwire-issues/issues/1028

If there's some existing core event listener that's getting triggered by the click when it shouldn't be, it would be better to update that listener to exclude the case according to the event target. E.g. at line 2696:

if($(event.target).hasClass('InputfieldHeaderAction')) return;