[wp-trac] [WordPress Trac] #33359: Custom fields in media modal javascript events are unbound after ajax save method
WordPress Trac
noreply at wordpress.org
Wed Aug 12 20:14:20 UTC 2015
#33359: Custom fields in media modal javascript events are unbound after ajax save
method
----------------------------------------+-----------------------------
Reporter: LindsayBSC | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 4.2.4
Severity: normal | Keywords:
Focuses: javascript, administration |
----------------------------------------+-----------------------------
'''Problem''':
Any javascript bound to a field created by the custom attachment fields
API (attachment_fields_to_edit) gets unbound (or removed) after the save
function is finished.
'''Replicate''':
You can replicate it by adding the following code into your theme's
functions.php or into a plugin file (update path to JS accordingly)
Form Fields & Save PHP functions
https://gist.github.com/Lindsayanng/81d2360c227ebc325325
Test javascript
https://gist.github.com/Lindsayanng/b6f52af6bbe35f7bd347
The above code will create custom fields at appear in the media modal
"details" sidebar. To test this, click the "Trigger JS Event" button. You
will see all input fields turn red.
Enter content into any of the default image attachment fields like 'title'
and 'caption' and as you switch between fields the save function is run
and the red background remains.
Update any content into a custom created field and when you switch between
fields the save function will trigger and you will see the js event that
created the red background on those fields is gone!
I have found that the JS events are unbound using both edit-attachment and
wp_ajax-save-attachment-compat' actions.
'''Solutions''':
I believe this has to do with how the javascript view is re-rendered after
the save function.
See screencast: http://cl.ly/0a401F0r0z2S
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33359>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list