70pw4a
Last Updated: June 09, 2016
·
5.111K
· marti1125
Yo

Datepicker for Backbone Form

https://github.com/eternicode/bootstrap-datepicker
https://github.com/powmedia/backbone-forms

    Backbone.Form.editors.DatePicker = Backbone.Form.editors.Text.extend({
            initialize: function(options) {
                Backbone.Form.editors.Text.prototype.initialize.call(this, options);
                this.$el.addClass('datepicker input-small-custom');
                this.$el.datepicker({

                }).on('changeDate', function(ev){                       
                     $(this).datepicker('hide'); //close when select a date
                });

            },

    getValue: function() {
        var value = this.$el.val();        
        return value;
    },      

    render: function() {
        Backbone.Form.editors.Text.prototype.render.apply(this, arguments);
        this.$el.datepicker({});
        return this;
    } 
});

in backbone form:

 var fields = Backbone.Model.extend({
    schema: {           
        date: { type: 'DatePicker'}        

    }
});
Say Thanks
Respond

2 Responses
Add your response

9823
50c94bce099849c47f0b424f32a50956

I tried your code and got the following error
Uncaught TypeError: Object [object Object] has no method 'datepicker' . I am not using any template just binding the form directly to an id.

over 1 year ago ·
9824
Yo
over 1 year ago ·