Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap datepicker hide after selection

How do I hide the calendar after a date is selected? Is there a specific function that I can use? My code below:

$('#dp1').datepicker({     format: 'mm-dd-yyyy',     startDate: '-15d',     autoclose: true,     endDate: '+0d' // there's no convenient "right now" notation yet }); 

Any help would be appreciated.

like image 905
jheul Avatar asked Jan 16 '14 01:01

jheul


People also ask

How do you hide a date picker?

Syntax: $(". selector"). datepicker("hide");

How do I stop bootstrap DateTimePicker from closing when I click outside?

To prevent closing before clicking outside, I delete hide function like this: $('#datepicker'). data('datepicker'). hide = function () {};


1 Answers

You can use event changedate() to keep track of when the date is changed together with datepicker('hide') method to hide the datepicker after making selection:

$('yourpickerid').on('changeDate', function(ev){     $(this).datepicker('hide'); }); 

Demo

UPDATE

This was the bug with autoclose: true. This bug was fixed in latest master. SEE THE COMMIT. Get the latest code from GitHub

like image 172
Felix Avatar answered Sep 20 '22 07:09

Felix