#27028 closed defect (bug) (fixed)
Custom fields in the Media Uploader added with attachment_fields_to_edit do not behave correctly.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 3.9 |
Component: | Media | Keywords: | has-patch |
Focuses: | javascript | Cc: |
Description
While trying to add a custom 'credit' field to the Media Uploader attachment fields, I used add_filter( 'attachment_fields_to_edit', function( $form_fields, $post ) to create the field and then add_filter( 'attachment_fields_to_save', function( $post, $attachment ) and update_post_meta to save the value of the field. This field does not behave the same as the default fields (title, caption, alt text, description) in the media uploader. Normally, when clicking from one field to the next, a background call is made which saves that information in the background while at the same time a waiting animation appears in the upper right hand corner of the media uploader modal to indicate to the user that something is processing. However, when clicking away from my custom credit field added with 'attachment_fields_to_edit', this animation does not appear. In addition, when the background saving is finished, the cursor moves back to the custom field, even if the user is typing something in a different field.
For example, say you typed 'photo by Bob' in the custom credit field. Then you click away from the field and start typing a description in the 'Description' field. Even if you do not make another mouse click and are typing in that field, when the background call to admin-ajax.php is finished, the cursor is re-focused on the custom field and the entire text there is highlighted so that if you were in the middle of typing you might end up over-riding the text that was previously in the credit field. This behavior does not happen with the default fields, only fields added with the add_filter('attachment_fields_to_edit').
I am not familiar with Backbone.js and I am not sure if the issue is because the HTML generated from attachment_fields_to_edit is not working correctly with the Media Uploader js code, or perhaps something in the media js code is not playing nice with the HTML or vice versa or something else entirely.
Attachments (1)
Change History (7)
#2
@
11 years ago
- Keywords reporter-feedback added
Hi @bshewmaker, thanks for the report. I'm not able to reproduce your issue in current trunk with no plugins and the Twenty Fourteen theme enabled.
Which screen are you seeing this issue on? I don't see any background updates occurring on the Edit Media view, only the heartbeat call, and my custom field appears to be treated as any other.
Can you share some example code that would help reproduce the issue?
#3
@
10 years ago
- Focuses javascript added
- Keywords has-patch added; reporter-feedback removed
- Milestone changed from Awaiting Review to 4.1
- Owner set to wonderboymusic
- Status changed from new to assigned
Gnarly as all of this is, it actually works fine.
27028.diff makes the spinner show up for compat fields.
Here is the PHP code I used to test:
function ___attachment_fields_to_edit( $form_fields, $post ) { $flavor = get_post_meta( $post->ID, 'pizza_flavor', true ); $form_fields['pizza'] = array( 'value' => $flavor, 'label' => 'Pizza Flavor' ); return $form_fields; } add_filter( 'attachment_fields_to_edit', '___attachment_fields_to_edit', 10, 2 ); function ___attachment_fields_to_save( $post, $attachment_data ) { update_post_meta( $post['ID'], 'pizza_flavor', $attachment_data['pizza'] ); return $post; } add_filter( 'attachment_fields_to_save', '___attachment_fields_to_save', 10, 2 );
#27029 was marked as a duplicate.