2

The current dom event model propagates the event from a leaf node (the source of the event) to the top root (document).

My question is this: Is there a way to trigger an event backwards? From body, make it go down the dom to the leaves?

I want to disable all form inputs in my form. They are all jquery ui widgets. I don't keep a reference of the elements in the main form component and when I submit I want to disable all of them. All my widgets bind to a custom dom event, called "field:disable".

Ja͢ck
  • 166,373
  • 34
  • 252
  • 304
Vlad Nicula
  • 3,455
  • 6
  • 31
  • 46

2 Answers2

0

Events can only bubble from leaf to root, not the other way around.

You should determine a common class that all your widgets have and then trigger the event manually:

$('.ui-widget').trigger('field:disable');
Ja͢ck
  • 166,373
  • 34
  • 252
  • 304
0

jQuery does not support event capturing, so I think you are stuck with event bubbling.

Why don't you do

$('#form input').trigger('field:disable')

if you do not want to propagate the event

$('#form input').triggerHandler('field:disable')
Community
  • 1
  • 1
Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
  • I was thinking that capture trigger would be less costing compared to a jQuery selector. Oh well, thanks for clarifying. – Vlad Nicula Mar 22 '13 at 10:10