trentrichardson / jQuery-Timepicker-Addon

Adds a timepicker to jQueryUI Datepicker
http://trentrichardson.com/examples/timepicker/
MIT License
2.66k stars 1.05k forks source link

Plugin is truncating the time value from the initial datetime value from the text field #750

Closed kasulachetu closed 10 years ago

kasulachetu commented 10 years ago

I am running to issues with adding value attribute to the input field. If I set the value attribute on the input field, the timepicker is not displaying the value in the input field, but it reads the value for the timepicker. See the example code on jsfiddle: http://jsfiddle.net/kasulachetu/7fug98m3/3/

HTML:

<input type="text" name="start_date" id="start_date" value="21 Aug 2014 01:00" />
<input type="text" name="end_date" id="end_date" value="25 Aug 2014 01:00" />

jQuery:

var startDate = $("#start_date"),
endDate = $("#end_date");
$.timepicker.datetimeRange(
    startDate,
    endDate,
    {
      minInterval: (1000*60*60),
      dateFormat: 'dd M yy', 
      timeFormat: 'HH:mm',
      start: {}, // start picker options
      end: {} // end picker options                 
    }
);

How can I fix it?

kasulachetu commented 10 years ago

As I was debugging this in the console, I found that #('#start_date').val() is also returning just the date, but $('#start_date').attr('val') is returning the actual value including the time part.

trentrichardson commented 10 years ago

I haven't seen this before, thanks for pointing it out. Can you see what $('#start_date').datetimepicker('getDate') returns? Wondering if it stems from this line:

https://github.com/trentrichardson/jQuery-Timepicker-Addon/blob/master/src/jquery-ui-timepicker-addon.js#L2100

These may need to change the .val() to .attr('val') here:

https://github.com/trentrichardson/jQuery-Timepicker-Addon/blob/master/src/jquery-ui-timepicker-addon.js#L1696

kasulachetu commented 10 years ago

It returns the timestamp (Thu Aug 21 2014 00:00:00 GMT-0400 (EDT)), including the timezone info which user may not have selected.

trentrichardson commented 10 years ago

Are you able to try changing this line to .attr('value')? If not it may be tomorrow before I am able to work up an example of this to test with the altered library.

https://github.com/trentrichardson/jQuery-Timepicker-Addon/blob/master/src/jquery-ui-timepicker-addon.js#L1696

kasulachetu commented 10 years ago

I tried, but it didn't seem to fix the issue.

trentrichardson commented 10 years ago

Ok, maybe tomorrow I can try to dig a little deeper.

trentrichardson commented 10 years ago

@kasulachetu Have a look at the dev branch, I have fixed this and added some range examples to the documentation page.

kasulachetu commented 10 years ago

Your changes fixed the issue. Is this the documentation page you are referring to? http://trentrichardson.com/examples/timepicker/

trentrichardson commented 10 years ago

The documentation in the dev branch is the one I was referring to, it is in dist/index.html. Once I merge dev with master I will update the live website with the latest stable version/docs.