Problem/Motivation

The media browser in the 2.0 version of the media module does not work in some situations.

Steps to reproduce original issue:
- install D7
- install media 7.x-2.0-unstable6+3-dev
- open the media browser on an file field
- select a document in the library tab
- click 'Submit'

Steps to reproduce remaining issue in beta1 release:
- install D7
- install media 7.x-2.0-beta1
- open the media browser on an image field
- select an image in the library tab
- click 'Submit'

Expected behaviour: selected file is saved in the field, browser closes.
Actual behaviour: the browser pops up an alert: "You have not selected anything!"

Proposed resolution

A fix has been merged to 7.x-2.x-dev. People using 7.x-2.0-beta1 can work around the issue by upgrading jquery to >= 1.8 (instead of the default 1.4) - for example by installing jquery_update.

Remaining tasks

None, assuming the fixes in 2.x-dev will end up in a stable release eventually.

User interface changes

None

API changes

None

Data model changes

None

Original report by aaronbauman

I'm not familiar enough with media module and its various complexities to even begin to offer a patch.

media modules 7.x-2.0-unstable6+3-dev

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AaronBauman’s picture

Component: Code » Media Browser
AaronBauman’s picture

adding: it's not clear from the OP, but I can select image files (.jpg, .png, .gif) files a-ok

AaronBauman’s picture

Status: Active » Needs review
FileSize
802 bytes

OK, I did found the culprit.
Previews for non-image files contain links (ie. <a> tags).
Then the media browser adds a wrapper <a> tag to the preview.
Nested <a> tags cause the javascript to fail.

This patch fixes the media browser preview by stripping various html tags, including <a>

GuyPaddock’s picture

Status: Needs review » Needs work

This breaks media players being used in the preview as well... for example, using a MediaFront player as the preview style will not work with this patch.

I would recommend changing the JavaScript to find the correct link rather than stripping all HTML tags other than the expected ones...

AaronBauman’s picture

So, having a media player inside an <a> tag is legal HTML?
Seems like that's asking for problems too.

stevector’s picture

Status: Needs work » Closed (won't fix)
FileSize
70.62 KB

Each file in the browser is rendered with the "media_preview" view mode. The a tags should be excluded there. I ran into this same problem and changed the settings at /admin/structure/file-types/manage/application/file-display/media_preview

I recommend using "Large filetype icon" instead of "Generic file."

josebrito’s picture

Status: Closed (won't fix) » Active

The patch on #3 worked fine for me and solved my problem. Why this is not included on the actual 7.x-2.x-dev release?

AaronBauman’s picture

If media ships with a view mode configuration that causes a UX bug, that's a bug.
Perhaps the patch in #3 is a little too brute force.

A more appropriate patch would be for media_preview view mode configuration to be fixed.

ParisLiakos’s picture

@#8 exactly.
We need a patch that does what is described @#6

MPetrovic’s picture

The issue is that when you leave everything at the defaults, the preview is rendered with the file_link theme. This is set by file entity. Media either needs to check for that theme and change it to something else, or provide configuration for the preview view mode for every file type.

AaronBauman’s picture

In addition to shipping with broken default configuration, allowing an administrator to break the media selector view by reconfiguring a file display is a poor user experience.

My patch from #3 is a sub-optimal approach, but does the job.

Here are some ideas for better approaches, if anyone else wants to take a stab:
* modify the media selector views plugin to use core views fields instead of its own display plugin
* modify the media selector views plugin to render files in a way that definitely won't break the javascript (ie. not dependent on admin configuration)
* use a post-render hook (or other possible hook) or javascript to fix the invalid DOM elements

Anonymous’s picture

I have got the same error. But i think its another reason. The field allows pdf files only, but it is not possible to submit an selected pdf. Only Images can be submitted. So i took a look in the media browser settings and found {"types":{"image":"image"}. I think there should be something like {"types":{"document":"document"}.
?

Anonymous’s picture

I didn't had a 'preview' viewmode. After creating this viewmode everything works well.
Without using the patch.

victoriachan’s picture

Like mentioned on comment on #3, this seems to be caused by anchor tags around non-image thumbnails.

I have managed to fix this by configuring the 'Preview' mode of the file display for the offending file type (this is Application on 7.x-2.0-unstable6), and unchecking all of the 'Enabled displays'. It was initially configured to display 'Generic file', which displayed the preview with the anchor tags around. I may have selected that display manually, can't remember if it was set as such out of the box.

anneeasterling’s picture

I found this thread after experiencing the same issue: using Media Browser to select PDF files (which happens to be in a Field Collection) when creating/editing a node.

Thanks to tips from Comments #3, #6 and #14, I fixed this on my site by setting the config here:
/admin/structure/file-types/manage/document/file-display/preview
to Large Filetype Icon.

Unlike victoriachan's experience, unchecking all "Enabled Displays" didn't work (that appears to be the default). And like victoriachan, I don't recall having made any config changes here, but probably an oversight on my part.

In any case, I concur with comments that the out-of-the-box functionality is confusing, but I think that better documentation may be a more elegant solution than trying to code for every use case.

Devin Carlson’s picture

This is essentially a duplicate of #1792738: Allow custom file view modes for WYSIWYG display.

There's two solutions here:

  • Assume/force the preview view mode to output an image.
  • Do not use links at all; every file could be wrapped in a <div> which holds the file's unique ID.
jpstrikesback’s picture

Just to stuff this info somewhere:

Using the latest releases (unstable-7) for both media & file entity:

I experienced the "You have not selected anything!" behaviour (as well as image previews in the media popup all being the default file icon enlarged). I tried setting various enabled displays on the file display as indicated above and tried unsetting them as indicated above, nothing worked, then I saw an error in js (I didn't copy it, apologies) indicating a view mode being undefined for wysiwyg-media.js and thought I wonder if I need to go and save my WYSIWYG settings and text formats again to reset some variables...so I did that and boom I could embed images...so I went back to my file display settings for the image file type and strangely enough all the new view modes had disappeared! I don't know if this will introduce some issues soon or what but I assume they were added by the update for good reason. and a save on either WYSIWYG or Text Format settings wiped them out.

EDIT:

Much of the crazy behaviour I experienced with file entity & media was due to some updates not applying but failing silently in drush, much ado, much borkedness and rolling back DBs later, I moved up to the latest dev release for both, and added the large file icon to the default file display and it works again.

Cheers,
JP

mstef’s picture

#3 seemed to have done the trick.

rwilson0429’s picture

Setting the preview view mode to 'Large filetype icon' at admin/structure/file-types/manage/document/file-display/preview worked for me.

apmsooner’s picture

@#19 - worked for me as well

OnkelTem’s picture

#6 works.
@stevector thanks.

Medial module itself should care about this when installing.

DamienMcKenna’s picture

I ran into this problem after upgrading a site from unstable3+38-dev to unstable7 - it was not physically possible to select any of the files. I tried changing the preview display mode for documents but it made no difference, but Aaron's patch from #3 resolved the problem for me.

aniebel’s picture

I concur with #22

bbinkovitz’s picture

There's a comment in the code that indicates that "Large filetype icon" is offered only for legacy support, which implies to me that it's deprecated. Is this something that would make it a poor choice for this solution?

ParisLiakos’s picture

where is that comment?

bbinkovitz’s picture

Lines 31-40 of media/includes/media.fields.inc

/**
 * Implements hook_field_formatter_info().
 *
 * Provides legacy support for the "Large filetype icon" file field formatter.
 * This was originally used when media entities contained file fields. The
 * current file entity architecture no longer needs this, but people may
 * have used this formatter for other file fields on their website.
 *
 * @todo Some day, remove this.
 */
ParisLiakos’s picture

nice...i guess we should rethink the approaches here..we also need a proper issue summary

bbinkovitz’s picture

When using the patch from 3, "URL to file" doesn't seem to insert anything into the WYSIWYG either.

Issue summary: The "You have not selected anything" error appears when inserting non-images via file browser. The patch in #3 is a messy workaround that, while effective, may break other things. It works by stripping tags. Only allowing "Large Filetype Icon" also gets around this problem, sort of, but it's a deprecated view mode.

Dave Reid’s picture

The large filetype icon is not being deprecated. I think the context of the comment in #26 is related to the Media field type which is in fact deprecated.

radiobuzzer’s picture

Hi, I am having this error, also for image files. After disabling media 1.0 and setting up media 2, the media browser only shows filetype icons instead of thumbnails, then also this error if you try to select one of them. This occurs in unstable7, sorry if it has been fixed in dev

mpgeek’s picture

Same situation as @DamienMcKenna at #22 (update media), and #3 fixes it. In fact every time i update media i have to patch again.

filsterjisah’s picture

both #3 and #9 works for me

bbinkovitz’s picture

What exactly is it that gets broken by using the patch in #3?

AaronBauman’s picture

The patch in #3 is a hack that does not address the core issue.

The core issue, from what I gather, is that the View that ships with Media and provides the "View Library" display defaults to using a file rendering method that's usually incompatible with Media Browser's javascript. Stripping the HTML from the rendered file is a brittle bandaid to address this particular symptom.

A proper fix would be for Media module to either ship a file display mode that worked with its display, OR provide a formatter/widget that rendered the file without causing javascript issues.

rwilson0429’s picture

I agree. The workarounds mentioned here puts a bandage on one problem but, creates usability issues.

arthurf’s picture

What version of file entity are people using who are experiencing this? Is this happening for clean installs (I can't duplicate it with a clean install) or only upgrades? Is it happening from 1.x -> 2.x and unstable X to current dev?

Just trying to gather some information for tracking this down.

mpgeek’s picture

@arthurf, i'm always working with a matched pair, and my current version is 2.x-unstable7. I haven't done a fresh, dry install for a while, so I can only confirm that this is a problem during updates.

arthurf’s picture

FileSize
1.42 KB

The problem seems to be in template_preprocess_media_views_view_media_browser(). It is wrapping already processed html in a link. This seems to work for images but not for non image content because the label is a link.

I'm not sure if this is the right fix but it seems to work for me. Changed the link to a wrapper div and adjusted the JS to find the wrapper instead of the link.

arthurf’s picture

Status: Active » Needs review
alexverb’s picture

That was exactly what I was thinking. Why use a link if you use javascript anyway? Looks like a good solution to me.

arthurf’s picture

FileSize
1.86 KB

Here's a cleaner fix which makes theme_media_thumbnail() for providing the right markup.

mpgeek’s picture

Updated from unstable7+4 to unstable7+(latest), then patched from #41. Works like a dream, and finally addresses the root of the issue (RTBC IMO).

Pierco’s picture

Status: Needs review » Active

Tested #41 and works for me.

arthurf’s picture

Status: Active » Needs review

I think we need cross browser testing on this as it's a change to the JS. Can somebody test with chrome/safari/firefox/ie?

ParisLiakos’s picture

would be nice if someone could check it with fangel's media multiselect

arthurf’s picture

FileSize
2.02 KB

Here's a reroll with some code cleanup

filsterjisah’s picture

Status: Needs review » Reviewed & tested by the community

#41 Tested in firefox, chrome, IE 7-10, safari and works in all

aaron’s picture

FileSize
45.21 KB

It works great, however, as you can see in the screenshot, the text of pdf files is repeated twice. However, I don't think that's enough to hold up this issue, so I would say this is RTBC, unless someone thinks otherwise.

arthurf’s picture

FileSize
105.68 KB

Even without the patch I get the duplicate label issue. We could adjust the theme_media_thumbnail() function to not display the label if it isn't an image maybe? Attached screenshot shows a mix of images and other file types in the browser with no patches applied.

mpgeek’s picture

The duplicate-label problem would be a nice fix in this patch as well. I've been using CSS to fix the issue in various places, but having the markup consistent with theme_media_thumbnail would be nice so the duplicate labeling is fixed "everywhere".

arthurf’s picture

mpgeek’s picture

Patch at #49 fixes the selection problem, issue mentioned at #51 fixes the duplicate title problem. Pleased.

gmclelland’s picture

#46 patch fixes the problem for me. Tested in Google Chrome and Firefox for Mac.

I'm using media and file entity 2.x-dev on Google Chrome Mac.

@rootatwc - I also tested the patch with fangel's media multiselect module. I'm seeing some strange behavior on field that uses fangels media multiselect browser:

1. On a file field set to unlimited values: In the media browser library I'm able to select files one at a time. Am I supposed to be able to select multiple?
2. on the media browser upload tab I am able to upload multiple files with plupload module with no problems.
3. In the media browser library tab: When I try to select one item and hit submit, it loads two media items in the field.

Note: When using just the patch in #46 without the Fangels media multiselect I do not see the problem listed in #3.

@mpgeek, #49 doesn't contain a patch.

ParisLiakos’s picture

Status: Reviewed & tested by the community » Needs work

Thanks gmclelland for testing..yes seems media_multiselect does not work with this patch.
I dont want to break multiselect ability from media browser again
checking now

ParisLiakos’s picture

Status: Needs work » Needs review
FileSize
2.42 KB

I was able to restore the multiple selection inside the browser..but after selecting multiple items and submitting the form..i only get one value in the field..but the same behavior applies before the patch...so we already managed to break this, somehow...i guess it would be nice to have some feedback from fangel, if someone can ping him

fangel’s picture

Someone called? :) I'll read through the issue, and take a look at the patch tonight so we can get this working.

ParisLiakos’s picture

heh that was fast:) thanks

fangel’s picture

I can't get it to fail. That is, everything seems to work for me (after I got my browser to reload the js file). And my review of the patch can't see why it should fail either.

I always start my test with the browser test-bed (media/browser/testbed), plug in the following for options "{multiselect: true}" and hit "Launch Media Browser". Then you should be able to verify that it returns a list of all items (it can be hard to decipher the huge json return, but it's possible).

And my multiselect widget (despite what people might think) relays 100% on the JS in Media. There is no JS related to the Media-browser in my module - the only custom JS in the module is what launches the browser. So given that the browser correctly returns all selected entries, the my multiselect module works correctly..

(This was checked with git checkouts of Media + File Entity from yesterday)

So how does this not work for you guys? I'll gladly keep trying to contribute to whatever issues you guys have with the media browser.

gmclelland’s picture

@fangel - thanks for looking into this

@rootatwc and @fangel - I just tested the patch in #55 in combination with fangel's module and everything is working correctly with the standard media browser and the multiselect media browser both as a field and when inserted in the WYSIWYG editor(Wysiwyg+CKeditor).

I tested on Google Chrome and Firefox - Mac.

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

ok, then glad it works for you, seems it is one of my other thousands of path i have applied^^

fangel’s picture

Rootatwc: you can email me a zip of your media module with all patches and I'll gladly try and figure out what's causing multi select to break for you...

ParisLiakos’s picture

Status: Reviewed & tested by the community » Fixed

thanks fangel, if i have a problem with it in somewhere else besides my dev instance i ll open an issue in you sandbox queue.
i went ahead and committed this:) thanks all
http://drupalcode.org/project/media.git/commit/e771336

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dalin’s picture

Attached is a patch against 2.0-unstable7 if anyone needs.

sheldonkreger’s picture

Status: Closed (fixed) » Reviewed & tested by the community

I have tested the patch in 64, it solves the problem in 2.0-unstable7.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1743040-64-2.0-unstable7.patch, failed testing.

ParisLiakos’s picture

Status: Needs work » Closed (fixed)

and its already commited

TBarina’s picture

I applied the patch in #64 but is doesn't fix the problem in 7.x-2.0-unstable7

dalin’s picture

I also found an issue with using the jQuery Uniform library. It does something to the button that opens the media browser that opens a second (unseen) media browser. This confuses media browser because the 'selected' item gets saved to one window, and the submit button's on the other.

So make sure you don't have Uniform getting in the way. My solution was:

$('a long list of selectors')
        .filter(function(){
          // Don't theme buttons that open the media browser.  Doing so opens a 
          // second (unseen) media browser and then you can't select anything.
          return $(this).parents('.field-widget-media-generic').length < 1;
        })
        .once('uniform')
        .uniform();
r2integrated’s picture

Just a FYI for folks who come across this late in the game like I did - #3 appears to actually fix the issue of not being able to select documents. #46 and #55 did *not* work for us.

Cyberschorsch’s picture

Status: Closed (fixed) » Reviewed & tested by the community

I am re-opening this issue.

This error is still occuring in the latest versions (dev and unstable). The patch posted in #3 is working for us quite well. Since it is working for other users, I suggest we commit patch #3

arthurf’s picture

@cyberschorsch the patch from 3 is pretty aggressive and could cause problems for some formatters.

Can you provide:
* what formatter you're using for the display when the error occurs
* is there anything in your js console
* an example of the html that is output for a single item in the browser

aaron’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Postponing the issue pending a report from the op.

Devin Carlson’s picture

rambazambi’s picture

Title: "You have not selected anything!" error message, when a selection has clearly been made » quick patch
Version: 7.x-2.x-dev » 7.x-2.0-unstable7
Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.85 KB

here is a quick patch for 2.0-unstable7

DamienMcKenna’s picture

Title: quick patch » "You have not selected anything!" error message, when a selection has clearly been made
Version: 7.x-2.0-unstable7 » 7.x-2.x-dev

Please don't change the "issue title" field unless you have a reason to, thanks :)

openstep’s picture

Hello,

when run
patch -p0 --dry-run <1881152_insert.2.diff
patching file includes/media.theme.inc
Hunk #1 FAILED at 82.
1 out of 1 hunk FAILED -- saving rejects to file includes/media.theme.inc.rej
patching file js/plugins/media.views.js
Hunk #1 succeeded at 67 with fuzz 1 (offset -8 lines).
patching file media.views.inc
Hunk #1 succeeded at 77 with fuzz 1 (offset -2 lines).

Any Idea what is wrong with the patch?

In my patch I deleted the a/ and b/ references and have put the patch in the root of the module.
I have also realized that in the patch it is fererrencing the function theme_media_thumbnail($variables) but the original file includes/media.theme.inc only has the function theme_media_admin_thumbnail($variables)

also I can not find this: includes/media.theme.inc.rej

diff --git includes/media.theme.inc includes/media.theme.inc
index f536deb..9e856b3 100644
--- includes/media.theme.inc
+++ includes/media.theme.inc
@@ -82,8 +82,13 @@ function theme_media_thumbnail($variables) {
$element = $variables['element'];
$destination = drupal_get_destination();

- // Wrappers to go around the thumbnail.
- $prefix = '

';
+ // Wrappers to go around the thumbnail.
+ $attributes = array(
+ 'title' => $element['#name'],
+ 'class' => 'media-item',
+ 'data-fid' => $element['#file']->fid,
+ );
+ $prefix = '
';
$suffix = '

';

caktux’s picture

Priority: Normal » Major

Patch in #75 works and looks like the best solution.

arthurf’s picture

Can you confirm that the current dev branch is not working? This fix went in already so either it needs revision or we're dealing with a different issue.

caktux’s picture

Status: Needs review » Closed (fixed)

My bad, you're right, I was on 2.0-unstable7... http://drupalcode.org/project/media.git/commit/e771336

DamienMcKenna’s picture

For anyone still experiencing this problem, after much debugging I discovered that the Styles module was changing the DOM structure to something the media browser wasn't able to work with. I'm continuing to debug the problem, I'll post more when I know more.

DamienMcKenna’s picture

So it turned out that the reason our site's users couldn't select items in the file browser was because the image file display (admin/structure/file-types/manage/image/file-display) was configured to use a file style directly, once I changed it back to the Image display style with the appropriate image style it worked again and I could select items in the media browser. Should I add a follow-on documentation task for this?

atracht’s picture

I'm not sure if this belongs here, but I found the issue for me was with AdvAgg #2111695: "You have not selected anything!" when not on page 1 (Media v2)

DamienMcKenna’s picture

For anyone using AdvAgg, I opened a new issue to dig into the problem: #2122237: Compatibility problem with Media module's media browser popup

ergophobe’s picture

Issue summary: View changes

Confirming - I had the same problem as Damien McKenna and his solution in #82 worked for *image* files. I believe this is due to a default setting in Panopoly (the default image display was set to a panopoly style)

For the issue with non-image files, the "Large Icon" solution worked without needing any patches.

cameron prince’s picture

This can also happen when the settings for the preview display (admin/structure/file-types/manage/image/file-display/preview) are incorrect.

seren10pity13’s picture

I had the same problem with 7.x-2.0-beta1, in these conditions :

- Click browse button : browser show-up normally (but overlay is reall black, almost no opacity)
- I can select my image
- But on submit, I get a "You have not selected anything!" alert
- When closing browser, an other one is still visible under (normal opacity of the overlay)
- With this one, I can select items and submit

If you're experiencing the same thing, report to the Browser window opens twice for field image issue instead.

brice_gato’s picture

What version of jQuery have you configured to be used? If you have jquery_update installed, switch to >=1.8
Media (7.x-2.*) browser seems require Jquery > 1.7

I'm using jQuery update 1.8 and issue was resolved!

kienan91’s picture

Thanks @brice_gato just update version Jquery > 1.7 problem fixed !

sfdrummer’s picture

Yes, @brice_gato is correct, installed jQuery Update and all working fine.

ph7’s picture

Yep, same here.

Activated 1.8 for the admin theme. Library also loads faster.
Hopefully nothing else is adversely affected by this change.

mstrelan’s picture

JQuery 1.8 fixed this for me too. Can we get this documented on the project page?

mpotter’s picture

So, increasing jQuery to 1.8 is not a viable solution. As noted in #1974774: Media Browser renders all tabs visible, it breaks the multiupload functionality. Also, weren't there still issues in the Views UI with jQuery 1.8?

I'll take a look at other solutions above, but this was a regression for me updating to the 2.0-beta1 media from 2.0-alpha4

tamnv’s picture

JQuery 1.8 fixed this for me too. Any other solution for this issue?

kaa4ever’s picture

Ran into the same issue, and planning to rewrite the current patches to the current beta version, I found out that this problem does not occur in 7.x-2.x. So guess a patch is already applied in the dev version?
For now, while developing, i'll use that checkout.

pieterdt’s picture

bumped into this issue as well after upgrading to beta1 from alpha release.

jsst’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
jsst’s picture

I can confirm the original issue where files could not be selected is resolved in 7.x-2.0-beta1.

But using the default jquery version neither files nor images can be selected in 7.x-2.0-beta1, you have to use jquery update to work around that. In 7.x-2.x-dev everything works as expected regardless of the jquery version used.

I've updated the issue summary.

rcodina’s picture

@jsst I confirm using the latest dev version solves the problem.

KeithC’s picture

Status: Closed (fixed) » Active

Rather than advising people to use a dev version as a workaround, is there any chance this could be added to a stable release please?

lazar.lehel’s picture

In my case the 7.x-2.0-beta2 version solves the problem.

rcodina’s picture

Status: Active » Fixed

If beta2 is released, then this is fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.