0
votes

I am having a hard time with setting up bootstrap-datepicker-rails inline calendar.

My form looks like this, this display nice inline calendar and hidden field for rails to set/update start_date on the model:

<%= form_for task do |f|%>
  <%= f.hidden :start_date %>
  <div id="picker"></div>
  <%= f.submit %>
<% end %>

tasks.coffee file:

ready = -> 
  $("#picker").datepicker().on 'changeDate', (e) ->
    $("#task_start_date").val(e.date)

$(document).on('page:change', ready) 

Strong parameters are set fine, model gets save/updated correctly.

The problem I have is that calendar doesn't show any date when the model is edited and I would like it to select the date that was previously save.

When I am editing the record saved with a start_field set up to 12 Feb 2015, hidden_field value is set to '2015-02-12 00:00:00.000000'

I have tried to add setDate line to task.coffee:

ready = -> 
  $("#picker").datepicker().on 'changeDate', (e) ->
    $("#task_start_date").val e.date

  $("#picker").datepicker 'setDate', $("#task_start_date").val()

$(document).on('page:change', ready) 

But it is not working as the format of the hidden_field is not correct. When I manually set the second argument for 'setDate' to '02-12-15' it is working.

Is there a way to change the format for 'setDate' method?

Should I change rails time zone for a local one?

Way datapicker expect date in %m-%d-%Y format?

I tried to play around with a different formats passed into $("#picker").datepicker(...).on 'changeDate', (e) -> line but I can't get it working! I give up. Some one help me please!

I hate playing with date formats and $%^&$ time standards:/

1

1 Answers

0
votes

FIX:

  • Changing column type to :date from :datetime on the task model.
  • Setting the format for datepicker to 'yyyy-mm-dd'