简体   繁体   中英

How do I use jquery datetimepicker with webpacker in rails 6

So far this isn't working Nothing happens when I click on the field in the form I have jquery-datetimepicker installed as a node module
application.js:

// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

require("@rails/ujs").start()
require("jquery")
require("jquery-datetimepicker")
//require("bootstrap-datepicker")
require("js.cookie")
require("turbolinks").start()
require("@rails/activestorage").start()
require.context('../images', true)
require.context('../stylesheets/fonts', true)
require("trix")
require("@rails/actiontext")

import "bootstrap"
// import "blueimp-gallery"
import "../stylesheets/application"
document.addEventListener("turbolinks:load", () => {
  $('[data-toggle="tooltip"]').tooltip()
  $('[data-toggle="popover"]').popover()

})

import JQuery from 'jquery';
window.jQuery = $;
window.$ = $;

// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)

_press_release_form.js:

$(document).ready(function () {

$('#showdate').datepicker();
$('#showtime').timepicker();

})

you are using require("jquery-datetimepicker")

it should be $('#showdate').datetimepicker() instead

document.addEventListener("turbolinks:load", () => {
  $('#showdate').datetimepicker()
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM