2

A click event on a link with the use-ajax class on it does not seem to propagate up the DOM. Is this true? If so, is there a setting that will allow it to propagate?

Not being a JS whizz, I'm struggling to see where the call is made (preventDefault? return false?) that blocks the propagation. I've had a look at misc/ajax.js and there is a setting element_settings.prevent that looks like it might be relevant, but I haven't found any documentation on this.

1

It's in Drupal.ajax.prototype.eventResponse, round about line 265:

// For radio/checkbox, allow the default event. On IE, this means letting
// it actually check the box.
if (typeof element.type != 'undefined' && (element.type == 'checkbox' || element.type == 'radio')) {
  return true;
}
else {
  return false;
}

It's hard-coded, but this is JS - you can just monkey-patch Drupal.ajax.prototype.eventResponse and get it to do whatever you like :)

  • Brilliant, thanks. Do you happen to know why "return false" is used instead of "preventDefault"? Seems to me that preventDefault would do what is intended and no more – naomi Mar 5 '14 at 11:52
  • Returning false is equivalent to running event.preventDefault() and event.stopPropagation(). If I had to guess, I'd say that's why they've done it - just for brevity – Clive Mar 5 '14 at 11:58
  • Sorry, you're asking why the use of stopPropagation() at all, aren't you...'fraid I don't know that one. Might be an oversight, might be intentional – Clive Mar 5 '14 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.