skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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')
    

  2. I added a new feature request for that in https://github.com/atatanasov/gijgo/issues/719

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search