Archana
Archana

Reputation: 103

How to hide the Bootstrap datepicker

I made the date field readonly but still we are able to select the date from datepicker. I tried

$('#date').datepicker("None");
$('#date').datepicker("disable");
$('#date').datepicker("destroy");

None of them works. But the below code worked partially. Like on click it is showing the calendar and getting hidden. I'm not able to select any date from the calendar. This is fine but even it should not show the calendar.

$('#date').on('click', function(){
    $('.datepicker').hide();
});

Upvotes: 0

Views: 5310

Answers (3)

user1928896
user1928896

Reputation: 673

If the #date is readonly, why initialize the datepicker? The following code should be enough: $('#date').attr('readonly', true)

EDITED to include the following solution to remove datepicker once it was initialized: $('#date').datepicker('remove');

Upvotes: 1

Rushee
Rushee

Reputation: 766

Check the JSFiddle :- JSFiddle

$('.myDatepicker').each(function() {
var $picker = $(this);
$picker.datepicker();

var pickerObject = $picker.data('datepicker');

//HIDE THE CALENDER
$picker.on('changeDate', function(ev){
    $picker.datepicker('hide');
});
});

Upvotes: 0

Ahmed
Ahmed

Reputation: 2266

have you tried

$('#date').hide();

Upvotes: 0

Related Questions