简体   繁体   中英

How to attach event handler in backbone forms

I am using Backbone form - https://github.com/powmedia/backbone-forms .

In few fields I am using custom template for a specific field. Lets say something like this

Now Lets say I want to attach a click event handler to "Add month". What is the best way to accomplish it. I see that Backbone.Form is extending Backbone.View which has accepts events object. But when I pass that while doing new Backbone.Form() it does't do anything.

You should be able to extend the Backbone.Form view to add your own custom events, like this

Backbone.Form.extend({
    events: _.extend(this.events, {
      'click .add-month': 'onClickAddMonth' 
    }),

    onClickAddMonth: function(e){
       // do something
    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM