Datepicker does not display the calendar

北慕城南 提交于 2019-12-03 06:42:39

I was experiencing the same issue. This is a turbolinks problem.

You can disable turbolinks at the source page that you're coming from by adding data-no-turbolink to the href or div, and this will get it working. i.e.

<%= link_to "Create New Form", sampleform_path, 'data-no-turbolink' => true %> 

See more details here, under the "Opting out of Turbolinks" section.

[EDIT] I think the better solution is to call your document.ready code during the page:change event also in coffeescript. Here is the code you can use:

$(document).on 'ready page:load', -> $('.date').datepicker({
    format: 'dd-mm-yyyy'
    autoclose: true
    todayHighlight: true
    language: 'fr'
});

I had the same issue with rails 5 and Jquery Autocomplete. I had my search box in my navbar and every time i went to a different page in my app my autocomplete with elasticsearch would break, that is not bring up all users associated with what i was typing. To fix I added this to my _nav.html.erb <nav class="navbar navbar-fixed-top navbar-inverse" data-turbolinks="false">. I tried it in my div just around the search box but, that didn't seem to work but, worked in the nav. Per the Turbolinks page: With Turbolinks, these events will fire only in response to the initial page load—not after any subsequent page changes".

https://github.com/turbolinks/turbolinks/issues/253

The jQuery UI date picker widget appends a shared element to the body which it expects will never leave the page, but Turbolinks removes that shared element when it rerenders. We satisfy that expectation by removing the shared element from the page before Turbolinks caches the page, and appending it again before Turbolinks swaps the new body in during rendering.

Additionally, returning to the cached version of a page that previously had date picker elements would result in those date pickers not being initialized again. We fix this issue by finding all initialized date picker inputs on the page and calling the date picker's destroy method before Turbolinks caches the page.

document.addEventListener "turbolinks:before-cache", ->
  $.datepicker.dpDiv.remove()

  for element in document.querySelectorAll("input.hasDatepicker")
    $(element).datepicker("destroy")

document.addEventListener "turbolinks:before-render", (event) ->
  $.datepicker.dpDiv.appendTo(event.data.newBody)

The simplest solution for this is use the method: :get in the link_to

<%= link_to "Create New Form", sampleform_path, method: :get %> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!