mardi 6 décembre 2016

Bootstrap Datepicker doesn't return selected dates after changeDate event within Ember.js

I created an Ember.js component called date-picker-multi.js using the Bootstrap Datepicker JavaScript plugin. I am trying to get the dates within both the input fields (from the date range) whenever the user selects a different date.

As per the Bootstrap Datepicker component's changeDate event, I should be able to get both the dates by accessing e.dates however, when I do this, I get an array with just one item in it like this:

[Fri Dec 09 2016 00:00:00 GMT+0530 (IST)]

This is what my date-picker-multi.js component looks like:

import Ember from 'ember';

export default Ember.Component.extend({
    tagName: 'div',
    maxViewMode: 1,
    autoclose: true,
    format: null,
    startDate: undefined,
    todayHighlight: true,
    datesDisabled: [],

    actualDates: null, // Store computer-friendly dates here

    didInsertElement() {

        this._super(...arguments);

        let self = this;

        // initiate jquery datepicker library
        let options = {
            maxViewMode: this.get('maxViewMode'),
            autoclose: this.get('autoclose'),
            todayHighlight: this.get('todayHighlight')
        };

        if (this.get('format')) {
            options.format = this.get('format');
        }

        if (this.get('startDate')) {
            options.startDate = this.get('startDate');
        }

        if (this.get('datesDisabled') && Ember.isArray(this.get('datesDisabled'))) {
            options.datesDisabled = this.get('datesDisabled');
        }

        this.$().datepicker(options).on('changeDate', function(e) {

            console.log(e.dates);
        });
    },

    willDestroyElement: function() {

        //remove all event handlers on this component
        this.$().off();
    }
});

Observe my console.log(e.dates); inside the changeDate event.

This is how I am calling the component in my Handlebars file:


    
    <span class="input-group-addon">to</span>
    


I can't figure out what the issue is. Does anyone know why this might be happening?




Aucun commentaire:

Enregistrer un commentaire