jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
359 stars 85 forks source link

Error when the time input has data #41

Closed krasi-georgiev closed 9 years ago

krasi-georgiev commented 9 years ago

http://screencast.com/t/QxJJY86biT

when I submit a form and one of the fields fails the server validation the time inout field will include the submitted value but datepair returns an error.

I tried to fix in the code , but not enough knowledge.

krasi-georgiev commented 9 years ago

Just now realised that this is a timepicker issue so will post the issue there

jonthornton commented 9 years ago

This appears to be a Datepair issue, not a timepicker issue.

I can't debug this without seeing code. Can you post a jsFiddle that demonstrates the problem, or provide steps to reproduce on the Datepair demo page?

krasi-georgiev commented 9 years ago

Here is a an example of a broken code: https://jsfiddle.net/dLLa6w2e/

vasically if the field has some data it brakes the timepicker.

there might be a way to pre populate the field with js , but I don't think that having some data in the field should brake the plugin.

jonthornton commented 9 years ago

You're initializing the datepair before initializing the timepickers and datepickers. This block

$('.date_time_pair').datepair({
    parseDate: function (el) {
        var utc = new Date($(el).datepicker('getDate'));
        return new Date(utc.getTime());
    },
    updateDate: function (el, v) {
        $(el).datepicker('setDate', v);
    }
});

initializes the datepair. It needs to go after the timepicker and datepicker calls. You can remove the second call to datepair().

krasi-georgiev commented 9 years ago

Thanks that worked.