Hi,

I'm trying to use the add-to-dropbox events but it doesn't seem work or maybe I not using it correctly .

  $('#hierarchical-select-0-wrapper').bind('add-to-dropbox', function() {
    alert('add to dropbox');
  });

nothing happens...

I noticed that if I use before-add-to-dropbox, it works only if I selected any items. If I select one it stops to work.

What i would like to do, exactly, is to call an ajax_form_callback like simple select

	$form['voc_1'] = array(
		'#type'             => 'select',
		'#title'            => t('Voc 1'),
		'#options'          => $term_array ,
		'#ajax' => array(
			'callback' => 'ajax_form_callback',
			'wrapper' => 'mymodule_result_div',
		)
	);

with a hierarchical_select instead simply select.

Regards

CommentFileSizeAuthor
#2 hs_test.zip1.67 KBjohaziel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Component: Miscellaneous » Code
Priority: Normal » Minor
Status: Active » Postponed

Confirmed. I don't have the time to fix this right now, though.

johaziel’s picture

Component: Code » Miscellaneous
Category: bug » task
Priority: Minor » Normal
Status: Postponed » Active
FileSize
1.67 KB

Hi again ...

I found this code in http://drupal.org/node/326300#comment-1216927

but nothing happends too !
what's wrong ? I'm testing with the example describe in the API.txt and a script javascript

I use :
drupal 7.7
firefox 6.0.2
ubuntu 11.04
all hierachical_select's modules are enable

somebody can test if it's work for you.
Thanks

Wim Leers’s picture

It's probably broken in D7. In D6, it should work just fine. Try it on a D6 test site to make sure this is a regression. That'd be helpful in moving this issue forward and would allow me to solve it quicker (since I wouldn't have to test that anymore).

johaziel’s picture

Component: Miscellaneous » Code
Category: task » bug
Priority: Normal » Minor
Status: Active » Postponed

Yes that's work fine on D6.

I tried to look in hierarchical_select.js if something was wrong but my level is not so high to see where the error is. If you have a track maybe I can do somethings.
I'm willing to participate in an attempt to fix this bug because it's important to me.

alexverb’s picture

Priority: Minor » Major
Status: Postponed » Active

Has this issue been looked at since? I'm also trying to find out why the events are not being fired. But not having any luck at the moment. Like johaziel said, maybe someone can point us in the right direction to find the culprit and fix this bug. Any help is appreciated.

Not having AJAX capabilities through an HS form element doesn't seem like a minor issue. Changing it to major.

alexverb’s picture

I've been comparing the javascript workflow of Hierarchical Select between D6 and D7. I've found that in D6 the event is triggered twice in the following code at line 446:

Drupal.HierarchicalSelect.triggerEvents = function(hsid, updateType, settings) {
  $('#hierarchical-select-'+ hsid +'-wrapper', Drupal.HierarchicalSelect.context)
  .trigger(updateType, [ hsid, settings ]);
};
 

It's triggered one time for "before-add-to-dropbox" and one time only for "add-to-dropbox". In D6 I'm also able to bind stuff to the event. So I assume this is the way it's supposed to work.

In D7 I pass the breakpoint 3 times:

  1. as expected "before-add-to-dropbox"
  2. a big pauze later I catch "add-to-dropbox"
  3. and again I catch "add-to-dropbox"

I think the problem is nearby. I'm still plowing through the javascript hoping someone may step in and help me out ;).

ckristo’s picture

Hi,

First of all: Thanks Wim Leers for your great module :-)

I don't think that the event isn't triggered, but I think the function the user bound to the event is not bound anymore. I bound a custom function using the following code when the DOM is ready:

$('#hierarchical-select-0-wrapper').bind('change-hierarchical-select', function() {
    console.log(" > Change!");
});

My function is called if I add the first element from the HS to the dropbox. Here's my debug output:

Trigger event ------------------------------------
'change-hierarchical-select':
 > Change!
--------------------------------------------------
POST <URL>

When I try to add another element from the HS to the dropbox, I get:

Trigger event ------------------------------------
'change-hierarchical-select':
--------------------------------------------------

So my function isn't executed anymore. I had a similar problem once developing my own module: I attached a change event to a select on page load using jQuery. Later on I replaced the complete HTML code of the select with an AJAX callback -- and the event didn't fire anymore. I had to re-attach the event after replacing the HTML.

The 'add-to-dropbox' event is called after the AJAX callback, and therefore the user bind is gone before the function is fired once...

I don't know the Drupal 7 AJAX API - but maybe Drupal 7 overwrites the complete HTML while Drupal 6 did only change certain innerHTML values.

-------------
Kind Regards
Christoph

mibfire’s picture

I did some research in this and what i have managed to figure out that drupal is not responsible for this.

In d7:

After ajax is called the whole box will be replaced.

Drupal.ajax.prototype.commands.hierarchicalSelectUpdate = function(ajax, response, status, hsid) {
  // Replace the old HTML with the (relevant part of) retrieved HTML.
  $('#hierarchical-select-'+ hsid +'-wrapper', Drupal.HierarchicalSelect.context)
  .parent('.form-item')
  .replaceWith($(response.output));
};

In d6:

Only the html inside the box will be replaced.

  // Replace the old HTML with the (relevant part of) retrieved HTML.
  $('#hierarchical-select-'+ hsid +'-wrapper', Drupal.HierarchicalSelect.context)
  .removeClass('hierarchical-select-wrapper-processed')
  .html($('.hierarchical-select-wrapper > *', $(response.output)));

So if it is replaced in d7 then the old events should be saved and attach to the new one.

There is a workaround for this if you wanna call your function after ajax replaces the content.

In jquery 1.7 there is an event called remove that is triggered if an html elem is removed. So you can attach a function to this.

For example:

$('#hierarchical-select-1-wrapper').on('remove', function() {
  // My custom code
});
mibfire’s picture

I found a solution for this.

You can use live function of jquery.

$('#hierarchical-select-1-wrapper').live('add-to-dropbox', function() {
  // My custom code
});

The document should be rewritten accordingly.

stefan.r’s picture

Category: Bug report » Task
Issue summary: View changes

It seems this is a documentation issue, not a bug?

stefan.r’s picture

Status: Active » Fixed

Committed a note to API.txt

  • stefan.r committed 1802c03 on 7.x-3.x
    Issue #1277068: events add-to-dropbox didn't work
    

Status: Fixed » Closed (fixed)

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