I've been able to reproduce this bug across multiple sites using different version of HS and varying sets of contrib modules.

The problem occurs when you use any HS widget on a node edit form (taxonomy or menu), and then use a file upload field (either adding a new file or removing an existing one). The entire set of theme css and js is loaded which causes quite a messed up looking edit form. This may also happen with other AJAX widgets, I haven't been able to test any others yet.

Marking this as critical because as it stands, HS is quite unusable.

Comments

acbramley’s picture

A themer I work with is debugging through this and trying to find out what is causing it, he's noted:

"When HS makes an ajax request it causes Drupal.ajaxPageState.theme to be overwritten with the front-end theme name. Then the next ajax request sends this info back, the system thinks your running the front-end theme so sends you all the css it thinks you now need but don't have"

acbramley’s picture

http://drupal.stackexchange.com/questions/5921/how-do-i-prevent-d7s-ajax... looks like this is a similar issue and was caused by the ajax request being outside the admin area

acbramley’s picture

As a workaround for the time being I've implemented hook_admin_paths() to tell drupal that the HS ajax path is an admin path:

/**
 * Implements hook_admin_paths().
 */
function my_module_admin_paths() {
  $paths = array(
    'hierarchical_select_ajax/*' => TRUE,
  );
  return $paths;
}
Georgique’s picture

@acbramley Does ajax upload works for your file field after choosing something in HS select?

acbramley’s picture

StatusFileSize
new103.51 KB
new53.23 KB
new55.13 KB

@Georgique yeah the file still gets uploaded, the issue is simply that the whole theme's css + js gets loaded, and since I'm on an admin page (i.e node/add/page) this adds the theme's css to the admin themes and causes the page to look all sorts of messed up. I'll post screenshots.

Note: You must have the node add form using the admin theme for this to occur.

Georgique’s picture

@acbramley I have another problem - HS breaks my AJAX file validation and upload. But I suspect that this is just my own problem on my install, so will check on other sites and if confirmed there only then create new issue.

danielbeeke’s picture

#3 works fine!

alexkb’s picture

StatusFileSize
new826 bytes

#3 works for me too, thanks heaps for posting this! I wanted to keep the HS stuff together in the same place, so put this hook into the HS module itself.

andregriffin’s picture

Status: Active » Reviewed & tested by the community

#3 fixed it for me.

acbramley’s picture

@alexkb thanks for rolling it into a patch :) Definitely makes sense to stick it in HS module if the same fix works for everyone! We need this committed...

wim leers’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/docroot/sites/all/modules/contrib/hierarchical_select/hierarchical_select.module
    @@ -2235,3 +2235,14 @@ function _hierarchical_select_special_item_exclusive($item) {
    +
    

    Extraneous newline.

  2. +++ b/docroot/sites/all/modules/contrib/hierarchical_select/hierarchical_select.module
    @@ -2235,3 +2235,14 @@ function _hierarchical_select_special_item_exclusive($item) {
    + * Implements hook_admin_paths(). See https://drupal.org/node/1671336#comment-6197346
    

    The "See …" message should be on the next line, preceded by a newline.

But … most importantly this is AFAICT the completely wrong way to fix it, this is just something completely unrelated that accidentally fixes the symptom.

The correct solution is this: http://drupal.stackexchange.com/a/38156. And if that doesn't work, there's a D7 core bug. IIRC there was something broken with D7's AJAX page state?

acbramley’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new835 bytes

Here's the patch finally, apologies for the wait, I just confirmed on a project that this fixed other issues too. I thought I could commit myself but looks like I don't have the access for it yet :P

darktek’s picture

Hi, why this is not working for me? Any thoughts I already implemented both code but still my css mess up when I try to upload a file , help please

Edit: Sorry, yes this works, I gotta cleaned my Cache in Database. Thx !!!

stefan.r’s picture

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