Reputation: 79
I am using datepicker from gijgo 1.9.14. I would like to know how to disable and enable it from javascript
$("#startDate").datepicker(
{
calendarWeeks: true,
uiLibrary: 'bootstrap4',
locale: 'pt-br',
value : '<?=date('d/m/Y')?>',
format:'dd/mm/yyyy',
iconsLibrary: 'fontawesome',
}
);
When I try
$("#startDate").prop('disabled',true)
The calendar icon is still active, so the user can use it to input data. Cant find anything on the official documentation to explain how to enabe/disable the control. Many thanks
Upvotes: 1
Views: 340
Reputation: 397
I added a new feature request for that in https://github.com/atatanasov/gijgo/issues/719
Upvotes: 0
Reputation: 79
found a way, not the prettiest one but it works...
//create datepicker
$('#startDate').datepicker(
{
calendarWeeks: true,
uiLibrary: 'bootstrap4',
locale: 'pt-br',
value : '<?=date('d/m/Y')?>',
format:'dd/mm/yyyy',
iconsLibrary: 'fontawesome',
}
);
Now with this function
function toggle_calendar( calendar , status )
{
let cal = $("#" + calendar);
let cal_icon = $(cal).next('span').children('button');
if (status == 'off' )
{
$(cal).prop('disabled', true);
$(cal_icon).prop('disabled', true);
}
else
{
$(cal).prop('disabled', false);
$(cal_icon).prop('disabled', false);
}
}
We can enable or disable the datepicker by
//to disable
toggle_calendar('startDate', 'off')
//to enable
toggle_calendar('startDate', 'on')
Upvotes: 1