#19675 closed enhancement (fixed)
Add a jQuery triggers to the widget save action
Reported by: | digitalnature | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.3 |
Component: | Widgets | Keywords: | has-patch |
Focuses: | Cc: |
Description
Line 241 (widgets.dev.js):
$(document).trigger('saved_widget);
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)
Change History (15)
#4
@
11 years ago
- Milestone changed from Awaiting Review to Future Release
- Severity changed from major to normal
#5
@
11 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: http://wordpress.stackexchange.com/q/138355/8521
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: https://gist.github.com/westonruter/9676069
#6
@
11 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.
This ticket was mentioned in IRC in #wordpress-dev by ocean90. View the logs.
11 years ago
This ticket was mentioned in IRC in #wordpress-dev by ocean90. View the logs.
11 years ago
#11
@
11 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?
#13
@
11 years ago
I have ignored 19675.patch for now. In future we should additionally pass a real Backbone model to the event handler.
Related: #21170