Search code examples
ruby-on-railsdatetimepickerbootstrap-datetimepicker

How to use bootstrap3-datetimepicker-rails gem on rails?


I have used the bootstrap3-datetimepicker-rails gem to select a date and datetime in my rails app.

My current implementation is:

HTML:

f.input :date, as: :string, :input_html => { :id => "datepicker" }
f.input :datetime, as: :string, :input_html => { :id => "datetimepicker" }

Javascript:

$(function () {
    $('#datepicker').datetimepicker({
      format: 'L'});
    $('#datetimepicker').datetimepicker();
  });

However, I have met some problem:

1.The datepicker for each id can only be use once, which means if I have two datepicker, I need to write two javascript code $('#datepicker1').datetimepicker(); and $('#datepicker2').datetimepicker(); . Is there a better way to reuse the code?

2.the datetimepicker didn't pull out the select dialog, I use it for inputing the datetime type attribute. When I click the field, the date and time is automate input into the field, the select dialog didn't appear.

3.Is there a way that just select the time but with a default date to fill in the datetime type attribute?

Thanks.


Solution

  • try this:

    <script type="text/javascript">
        $('.datetimepicker').datetimepicker({});
    </script>