Nerian / bootstrap-datepicker-rails

A Datepicker for Twitter Bootstrap, integrated with Rails assets pipeline
MIT License
649 stars 182 forks source link

Adopt to work with rails #125

Closed garmoshka-mo closed 8 years ago

garmoshka-mo commented 8 years ago

Control is nice, but it requires nightmare with Date strftime etc.. while working with control. It requires adoption for easy pass Date object to control and receive convenient date value on server (e.g. unix timestamp) without complex conversions (that would be rails style)

related to: https://github.com/eternicode/bootstrap-datepicker/issues/373

garmoshka-mo commented 8 years ago

Everyone who uses this control must do something like this (or even more complicated, when wasn't lucky to find some more less fast approach)

              <%= text_field_tag nil, @date_end.try(:strftime, '%m/%d/%Y'),
                                 {:'data-provide' => 'datepicker', class: 'form-control'} %>
              <%= hidden_field_tag :date_end, @date_end %>
  $('[data-provide="datepicker"]')
    .on('changeDate', function(e){
      $(e.target).next().val(
        e.format('yyyy-mm-dd')
      );
    });

something like this should be embedded to gem

Nerian commented 8 years ago

Configuring the default format can be done like this:

https://bootstrap-datepicker.readthedocs.io/en/stable/#configuration

garmoshka-mo commented 8 years ago

@Nerian default format will worsen user experience (standard rails format 2016-09-21 - convenient for programmers, not other people)

Nerian commented 8 years ago

There are many time formats. In order to present the date in the right format, I would suggest that you use the i18n library. You can use it to both parse the input and render the output in the right format.