LoginSignup
2

More than 5 years have passed since last update.

jQueryとbootstrapのDatePickerを同時に使う方法

Posted at

目的

jQueryとbootstrapのDatePicerを合わせて使う

経緯

既存のシステムがjQueryのDatePicerを使用しているが、
期間のフィールドを追加する事となり、jQueryのDatePicerではフィットする機能がなかったため、
bootstrapのDatePicerを使用する事となった。

jQuery DatePicerの呼び出し方

filename.rb
$('#datepickerjQuery').datepicker();

BootstrapDatePicerの呼び出し方

filename.rb
$('#datepickerBootstrap').datepicker();

え?宣言のやつが同じなの?
そもそも一緒に使っちゃダメなの?
案の定後に実行したDatePicerのオブジェクトになった。

解決方法

bootstrap側を以下のコードに修正

filename.rb
$.fn.bootstrapDP = $.fn.datepicker.noConflict();
$('#datepickerBootstrap').bootstrapDP();

一応動くみたいだけど、noConflictの説明がわからぬ・・・
bootstrapのdatepickerを取り出して別名にしてやってるようなイメージかな。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2