TangoKilo TangoKilo - 9 months ago 53
Javascript Question

Jquery Datepicker Rails 3 date format issue

I am trying to use a JQuery UI datepicker for a form for creating an event.

The form itself is rendering fine and if I use the normal rails date_field the information is saved without any issue. However when I try to use the datepicker, it states that the form can't be blank, even if I've picked a date. I realize that this is due to a difference in the format of the dates used by rails and and datepicker, so I've tried the following code:

dateFormat: "yyyy-mm-dd"

But that doesn't seem to have worked. The date is still displaying in the datepickers default format, and is passing that format as a parameter, which results in an error. Any pointers would be appreciated!


I had a similar problem a few months ago.

Try this format:

$(function (){
$('#dateField').datepicker({ dateFormat: 'D, dd M yy' });

It is working fine with all my Rails applicatons.


Also make sure the datatype of the column where you are saving the date (on the database) is set as string and not as date.