Nerian / bootstrap-datepicker-rails

A Datepicker for Twitter Bootstrap, integrated with Rails assets pipeline
MIT License
649 stars 182 forks source link

Turbolinks seems to mess things up #106

Closed ghost closed 8 years ago

ghost commented 9 years ago

I have turbolinks enabled (at least for now) and everything works fine from a regular page load, but if I come from another page, the calendar does show up, but when I click outside of the calendar to close it down the value of the field becomes blank again. I don’t know if anyone else is having that issue. I probably should just not use turbolinks, it’s my first time trying it out.

ghost commented 9 years ago

It only seems to happen if autoclose is set to false. Changing autoclose to true fixes the problem. Weird.

svavantsa commented 9 years ago

I still don't understand why you are suspecting turbolinks.

Surya Avantsa On Aug 24, 2015 7:31 PM, "Patrick Paul-Hus" notifications@github.com wrote:

I have turbolinks enabled (at least for now) and everything works fine from a regular page load, but if I come from another page, the calendar does show up, but when I click outside of the calendar to close it down the value of the field becomes blank again. I don’t know if anyone else is having that issue. I probably should just not use turbolinks, it’s my first time trying it out.

— Reply to this email directly or view it on GitHub https://github.com/Nerian/bootstrap-datepicker-rails/issues/106.

ghost commented 9 years ago

I suspect turbolinks because I only get the problem if I navigated from another page (using turbolinks). If I load the page with the date picker directly (thus this was a normal request, not an xhr), I don’t have the issue.

Nerian commented 9 years ago

Have you set up the initializer like this?

$(document).on('page:change', function(){
 $('.datepicker').datepicker();
});
ghost commented 9 years ago

No I’m initializing it using the data attributes. Maybe that’s the problem... but the datapicker does show up though, it just doesn’t behave nice when you select a date and then click outside of it.

wellington1993 commented 8 years ago

Eu tenho o mesmo problema. Depois de clicar fora do input o valor do mesmo desaparece. I have the same problem. After clicking outside the input the value of it disappears.

wellington1993 commented 8 years ago

The origin of the problem is multiple calls for the datepicker method in same html element. This was my solution:

$('.datepicker-js').datepicker({ clearBtn: true });

$( ".datepicker-js" ).removeClass( "datepicker-js");

"br is br.. always"

chris-sun commented 8 years ago

I also encountered this problem. With "turbolinks" enabled and visiting a page from another page in Rails, the datepicker( ) was not appearing. If you refresh, the page the datepicker( ) works. But visiting from another page it didn't work.

I temporarily disabled turbolinks by adding the "data-no-turbolink" attribute to the body tag, like such:

<body data-no-turbolink>
Nerian commented 8 years ago

Make sure that you are making the datepicker call inside a page:change handler.

$(document).on('page:change', function(){
 $('.datepicker').datepicker();
});