Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is a problem with the fake submit handler in the media browser (views) library.
If you don't select anything it alerts you then loads the homepage in the iframe due to the click event not being cancelled. It also adds the click handler onto the fake buttons as many times as you click around in the library. So if you click through a few pages n times without selecting anything and click submit it actually executes the submit handler n+1 times.
The event handler duplication can be fixed with
$('a.button.fake-submit', this).once().bind('click', Drupal.media.browser.submit);
$('a.button.fake-cancel', this).once().bind('click', Drupal.media.browser.submit);
The event bubbling can be fixed with a return false .
Drupal.media.browser.submit = function () {
// @see Drupal.media.browser.validateButtons().
var buttons = $(parent.window.document.body).find('#mediaBrowser').parent('.ui-dialog').find('.ui-dialog-buttonpane button');
if ($(this).hasClass('fake-cancel')) {
buttons[1].click();
}
else {
buttons[0].click();
}
// return false to prevert the default anchor location
return false;
}
Comment | File | Size | Author |
---|---|---|---|
#1 | media-browser-library-fake-submit-handler-1317098-1.patch | 979 bytes | aaron |
Comments
Comment #1
aaron CreditAttribution: aaron commentedworks as advertised; here's a patch.
Comment #2
aaron CreditAttribution: aaron commentedI take it back, this patch actually breaks the browser functionality, so that it no longer allows for any selection of media to be submitted.
Comment #3
aaron CreditAttribution: aaron commentedNo, I'm sorry, false alarm. There was something else going on, I'm not sure what, but after refreshing the page (which had been open for some time), it all start working again.
Comment #4
amateescu CreditAttribution: amateescu commentedThere's another nasty issue that's fixed by this patch: #1319846: Cancel returns homepage in iFrame
Confirming the RTBC status :)
Comment #5
Dave ReidTested and confirmed. Committed to 7.x-2.x only with http://drupalcode.org/project/media.git/commit/635ee16. Thanks Jamie, Aaron, and Andrei!
Comment #6
veleiro CreditAttribution: veleiro commentedThank you, works as stated