11

I can't get the following event to attach to my element.

events = {
   "change .date-selector .date-range": "dateRangeSelectionChanged"
}

Is this supported at all in Backbone.js? Or am I using a wrong syntax?

riksof-zeeshan
  • 531
  • 9
  • 27
orad
  • 15,272
  • 23
  • 77
  • 113
  • your syntax looks fine: http://backbonejs.org/#View-delegateEvents – Scott Bartell Apr 12 '13 at 07:57
  • 1
    Are you able to go to the console window and use jQuery to select your elements. $(".date-selector .date-range").length this should return at least 1. Also check to see if the dateRangeSelectionChanged has the correct spelling and camel case format. I would also check either using the developer tools in IE or FireBug in FireFox and check to see if you see any error messages. – Kalpers Apr 15 '13 at 01:01

3 Answers3

23

You can separate the selectors by comma(',')

events: { "change .date-selector,.date-range": "dateRangeSelectionChanged" }
techvineet
  • 5,041
  • 2
  • 30
  • 28
  • 1
    Good tip. However, I think that would do a logical `OR` than `AND`, to do and `AND` selector separate them by dots and no spaces in between. Please correct me if I'm wrong as I haven't tried this. – orad Mar 03 '14 at 22:51
6

To select upon multiple classes you should use:

events = { "change .date-selector.date-range": "dateRangeSelectionChanged" }

Note the removed space between classes

user2846569
  • 2,752
  • 2
  • 23
  • 24
0

I think your problem is that you have an equals operator where you should have ':'

App.Namespeace.BestViewEver = Backbone.View.extend({
  events : { 
    "change .date-selector .date-range": "dateRangeSelectionChanged"
  }
});
cbaigorri
  • 2,467
  • 25
  • 26
  • Thanks for the answer. I forgot to mention that this is TypeScript code and equal sign is valid there. I don't have it anymore in my app so don't know what was the problem but Kalpers' comment is useful. – orad Jul 11 '13 at 06:35