Reputation: 1785
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:
$(function(){
$("#dateField").datepicker({
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!
Upvotes: 5
Views: 4278
Reputation: 120
The answer is outdated, with Postgres and a Datetime field I've used
{format: "dd/mm/yyyy"}
and it did work.
Upvotes: 0
Reputation: 10769
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.
EDIT
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
.
Upvotes: 4
Reputation: 1963
Please clarify what doesn't work? The calendar doesn't appear? Try this code
jQuery(document).ready(function($) {
$("#dateField").datepicker({
dateFormat: "yyyy-mm-dd"
});
})
And what is default kind of format?
Upvotes: 2