I have the following code:
$('.custom_datepicker_selector').datepicker({
weekStart: 1
})
.on('changeDate', function(en) {
var correct_format;
correct_format = en.date.getFullYear() + '-' + ('0' + (en.date.getMonth() + 1)).slice(-2) + '-' + ('0' + en.date.getDate()).slice(-2);
$('.custom_datepicker_selector').datepicker('hide');
return $(this).parent().find("input[type=hidden]").val(correct_format);
});
This displays the date format just like I want it to. However it only does so after I click on the datepicker, not initially.
Initially this date is shown:
2013-02-17
and after I click on it I get this:
17/02/2013
How can I display the correct date immediately? (the code above is in the .ready
I created a jsFiddle for this: http://jsfiddle.net/jwxvz/
This was more a rails problem than a javascript:
I followed abu advice and did it like this in rails:
<%= f.input :order_date, :as => :custom_datepicker, :input_html => { :value => localize(@client_order.order_date) } %>