Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap datepicker not close automatically after picking a date

I use the latest Bootstrap datepicker.js. All works fine except that when I pick a date from the drop down, it does not automatically close it. I searched web and tried to use the following function in my javascript like the following:

 $('#selectDate').datepicker({     autoclose: true }).on('changeDate', function (ev) {     (ev.viewMode == 'days') ? $(this).datepicker('hide') : '';       }); 

but when i use Google Chrome Dev tools, I realized that ev.viewmode was undefined. I am not sure how to move forward.

like image 237
AlliceSmash Avatar asked Mar 19 '14 17:03

AlliceSmash


People also ask

How do I close Datetimepicker after selecting date?

$(document). mouseup(function (e) { $('#example1'). Close(); });

How can I hide datepicker after selecting date in jQuery?

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

How do I keep my datepicker open?

You have to use . show() method to keep your dateTimePicker visible, note that all the DateTimePicker's functions are reachable via the data attribute e.g.

How do I display only the year in datepicker?

I will suggest to add formate on datepicker as "YYYY" so it will only show years inside it.


1 Answers

I added autoclose: true, (with semi comma at the end and it works)

 $('.datepicker').datepicker({     format: 'dd/mm/yyyy',     todayHighlight:'TRUE',     autoclose: true, }) 
like image 162
Chaitanya K Avatar answered Sep 21 '22 08:09

Chaitanya K