現在、datetimepickerで予約機能を作っているのですが、datetimepickerが表示されない問題が
おきましたので、ご相談させてください。
stackoverflowやこちらの過去の投稿も参考にしたのですが、やはり難しく、ご相談させていただきたい次第です。
◾️ 以下のサイトを参考に作成しております。
◾️ 制作環境
gemfile
gem 'simple_form'
gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.17.47'
coffee script(calendar.coffeeとしています。)
init_datetimepciker = -> (-> $(".form_datetime").datetimepicker locale: "ja", format: 'YYYY/MM/DD hh:mm:', sideBySide: true autoclose: true, todayBtn: true, pickerPosition: "bottom-left", ) $(document).ready -> init_datetimepciker() $(document).on "ready page:load", init_datetimepciker()
config/initializers/date_time_picker_input.rb
class DateTimePickerInput < SimpleForm::Inputs::Base def input template.content_tag(:div, class: 'input-group date form_datetime') do template.concat @builder.text_field(attribute_name, input_html_options) template.concat span_remove template.concat span_table end end def input_html_options super.merge({class: 'form-control', readonly: true}) end def span_remove template.content_tag(:span, class: 'input-group-addon') do template.concat icon_remove end end def span_table template.content_tag(:span, class: 'input-group-addon') do template.concat icon_table end end def icon_remove "<i class='glyphicon glyphicon-remove'></i>".html_safe end def icon_table "<i class='glyphicon glyphicon-th'></i>".html_safe end end
html.erb
<label>予約カレンダー</label> <div class="input-group"> <%= f.input :start_date, as: :date_time_picker, class: "form_datetime", placeholder: '日程と時間を選択してください。' %> </div>
色々と試してみましたが、打つ手なしの状態になりましたので、ご助言をいただけると幸いです。
あなたの回答
tips
プレビュー