Make WordPress Core

Opened 13 years ago

Closed 10 years ago

Last modified 10 years ago

#19675 closed enhancement (fixed)

Add a jQuery triggers to the widget save action

Reported by: digitalnature's profile digitalnature Owned by: ocean90's profile ocean90
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.3
Component: Widgets Keywords: has-patch
Focuses: Cc:


Line 241 (


or something...

This way we could nicely hook our own js on that "saved_widget" event, instead of stuffing our js inside the widget form function.

This is relevant for all events created by WordPress in the administration area, not just widget-save.

Think of it like "add_action" for javascript...

Attachments (1)

19675.patch (1.8 KB) - added by ocean90 10 years ago.

Download all attachments as: .zip

Change History (15)

#1 @scribu
13 years ago

  • Cc scribu added

#2 @johnbillion
13 years ago

  • Cc johnbillion@… added

#3 @dgwyer
11 years ago

  • Cc d.v.gwyer@… added

#4 @ocean90
10 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from major to normal

Think of it like "add_action" for javascript...

Related: #21170

#5 @westonruter
10 years ago

Without a specific event which fires when a widget form gets replaced, it seems the de facto workaround is to hack jQuery.ajaxSuccess with checks for whether the the request for updating the widget. See an example at:

In #27491 I've just supplied a patch which adds a widget-form-update jQuery event which fires on the widget's root element whenever the form gets updated (i.e. when it is saved on the widgets admin page), and when this event happens the widgets can re-initialize any dynamically-generated fields (such as Chosen select fields). The event is also triggered in the customizer, where there are both hard updates and soft updates depending on whether it is detected that live updates are supported.

For an example of how such a widget may use this widget-form-update, see this sample plugin:

#6 @ocean90
10 years ago

  • Milestone changed from Future Release to 3.9
  • Owner set to ocean90
  • Status changed from new to accepted

Moving to 3.9 because of #27491.

10 years ago

This ticket was mentioned in IRC in #wordpress-dev by ocean90. View the logs.

10 years ago

#8 @ocean90
10 years ago

In 27909:

Widget Customizer: Improve support for dynamically-created inputs.

  • Re-work how and when widget forms get updated.
  • Replace ad hoc hooks system with jQuery events,
  • Add widget-updated/widget-synced events for widget soft/hard updates.
  • Enter into a non-live form update mode, where the Apply button is restored when a sanitized form does not have the same fields as currently in the form, and so the fields cannot be easily updated to their sanitized values without doing a complete form replacement. Also restores live update mode if sanitized fields are aligned with the existing fields again.

Note: jQuery events are *not* final yet, see #19675.

props westonruter.
see #27491.

#9 @westonruter
10 years ago

  • Keywords has-patch added

This ticket was mentioned in IRC in #wordpress-dev by ocean90. View the logs.

10 years ago

#11 @renak-zillow
10 years ago

It's nice to see the widget-updated/widget-synced/widget-added events in the customizer. Will those be implemented into the Widgets admin page as well?

#12 @ocean90
10 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 27969:

Widgets: Trigger jQuery events for widget updates.

  • widget-added when a widget is added to a sidebar
  • widget-updated when a widget is updated

A jQuery object of the widget is passed along to the event handler. Same events are used in the Widget Customizer, see [27909].

fixes #19675.

#13 @ocean90
10 years ago

I have ignored 19675.patch for now. In future we should additionally pass a real Backbone model to the event handler.

#14 @ocean90
10 years ago

#19587 was marked as a duplicate.

Note: See TracTickets for help on using tickets.