Quick question regarding delegateEvents in a View - can we specify multiple event bindings in a single event definition?
For example, instead of:
'keyup .text-input': 'textEvents',
'keydown .text-input': 'textEvents',
'focusin .text-input': 'textEvents',
'focusout .text-input': 'textEvents',
'click .text-input': 'textEvents',
...
Is this possible?
'keyup keydown focusin focusout click .text-input': 'textEvents',
No, you can't do that. From the fine manual:
Events are written in the format
{"event selector": "callback"}
The event is implicitly a single word (just like in jQuery and the DOM events) whereas selector can be any jQuery-style selector. Furthermore, the keys in this.events are parsed using this regex:
var delegateEventSplitter = /^(\S+)\s*(.*)$/;
so the event is the first component and only the first component.
You could build the events object yourself and call delegateEvents by hand with something like this:
var catch = ['keyup', 'keydown', 'focusin', 'focusout', 'click'];
var events = { };
_(catch).each(function(ev) { events[ev + ' .text-input'] = 'textEvents' });
this.delegateEvents(events);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With