I'm creating a custom search module in which a user can add multiple filters via AHAH calls. The module starts off with one filter loaded, which contains an HS taxonomy field. Clicking the "add filter" button makes an AHAH call to get another filter. When the new filter comes in, the new HS field appears inside it, but the "You don't have Javascript enabled." message box appears with it and doesn't go away. The "onchange" behaviors are bound to the field, but making a change gives the Javascript error "Drupal.settings.HierarchicalSelect.settings[_hsid] is undefined (line 246)."

Is using AHAH to create new HS elements supposed to be supported?

CommentFileSizeAuthor
#6 Drupal.settings.HierarchicalSelect.png82.23 KBwim leers

Comments

wim leers’s picture

Category: bug » support
Status: Active » Fixed

It's supported. But you haven't added the .js file yet that is needed to make HS work. This is Drupal core's fault, really. But you can work around it by including the file yourself in advance.

jberube’s picture

I should have mentioned that on the initial page load there is already an HS select and it's working fine. When you AHAH in a new HS field though, the new one doesn't initialize. Since the page is originally loaded with an HS field, the JS files "hierarchical_select.js" and "hierarchical_select_formtoarray.js" are already loaded.

jberube’s picture

When you bring in new fields don't you have to initialize them somehow?

jberube’s picture

If I re-run Drupal.HierarchicalSelect.initialize() after the new HS fields are brought in, the "No JS" message goes away, but when you make a selection on the HS field, the AJAX response is this:

Fatal error: Unsupported operand types in /Users/admin/Sites/sitename/includes/common.inc on line 2835

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Fixed » Postponed (maintainer needs more info)

Huh? You shouldn't have to call .initialize() yourself. For some time, the D6 version of HS's JS uses Drupal.behaviors, which should do this automatically. Please verify that you have version 1.88 of hierarchical_select.js.

wim leers’s picture

StatusFileSize
new82.23 KB

Also, please ensure that Drupal.setting.HierarchicalSelect gets updated through AHAH. There should be a series of settings in there for each HS instance.

I.e. if you've got one HS on the page, it should have id 0 and you should have:
Drupal.setting.HierarchicalSelect.settings[0]

I.e. if you've got two HSs on the page, they should have ids 0 and 1 and you should have:

Drupal.setting.HierarchicalSelect.settings[0]
Drupal.setting.HierarchicalSelect.settings[1]

See the attached screenshot for clarification.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

This is already working in the patch I posted a couple of days ago in http://drupal.org/node/342991. You can look there for examples. This is pretty advanced stuff though: Drupal doesn't make it easy (enough) yet.

You need a good understanding of how Drupal.settings, drupal_add_js(), page refreshes and AHAH loads interact. I don't have the time to explain this in great lengths, so if the above wasn't enough for you, you'll have to learn from that patch. I hope it's enough. If not, I hope for your understanding.