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);
});
Displays the date format the way I want. However, this only happens after I click the datepicker button, and not initially.
Initially, this date is displayed:
2013-02-17
and after I click on it, I get the following:
17/02/2013
How can I immediately display the correct date? (the code above is in .ready
I created jsFiddle for this:
http://jsfiddle.net/jwxvz/
This was a rails issue than javascript:
I followed Abu's advice and did it like this on rails:
<%= f.input :order_date, :as => :custom_datepicker, :input_html => { :value => localize(@client_order.order_date) } %>
source
share