I'm a newbie full of hope and amazed with Ruby on Rails 4. In my application, I need the user to input a range of dates. For this, I found the bootstrap-datepicker-rails gem very sexy. It basically works fine for indivdual dates, but I can't manage to get what I want talking about a date range :
The start date default is today
The end date default is today + 1 year, and has to be greater than the start date.
The date format is dd/mm/yyyy
I started with this piece of code which works well :
<div class="field">
<%= f.label :active_from %><br>
<%= f.text_field :active_from, 'data-behaviour' => 'datepicker', 'data-date-format' => 'dd/mm/yyyy'%>
<script type="text/javascript">
$('[data-behaviour~=datepicker]').datepicker();
</script>
</div>
<div class="field">
<%= f.label :active_to %><br>
<%= f.text_field :active_to, 'data-behaviour' => 'datepicker', 'data-date-format' => 'dd/mm/yyyy'%>
<script type="text/javascript">
$('[data-behaviour~=datepicker]').datepicker();
</script>
</div>
But trying to implement in rails the date range input examples of code found on the original documentation @github, I mess up : no interaction between star and end dates.
<div class="input-daterange">
<%= f.text_field :active_from, 'data-behaviour' => 'datepicker', 'data-date-format' => 'dd/mm/yyyy', 'value' => DateTime.now.strftime("%d/%m/%Y") %>
<span class="add-on">to</span>
<%= f.text_field :active_to, 'data-behaviour' => 'datepicker', 'data-date-format' => 'dd/mm/yyyy', 'value' => (DateTime.now + 1.years).strftime("%d/%m/%Y") %>
<script type="text/javascript">
$('[data-behaviour~=datepicker]').datepicker();
</script>
</div>
Can you please help me convert my 2 dates selection into a range selection ? Thanks a lot !
Best regards,
Fred