Search code examples
javascriptarraysdatepickerdatetimepickertimepicker

Timepicker JS change option value after loaded


Timepicker JS change option value after loaded.

I need to change the value of the disabled option dynamically. But I am not able to update this value.

Could someone help with this?

I need to open the timepicker.open value to be changed

thank you very much.

window.time = ''

$('#id_dia').on('click', function (event) {
    timepicker.open
    window.time = [true, [8,0], [10,11]]  <---- This value always changes
});

var timepicker = $('#time')
    .pickatime({
        format: 'HH:i',
        formatSubmit: 'HH:i',
        hiddenName: true,
        min: [7, 30],
        max: [20, 30],

        disable: window.time,   <-------
    })
    .pickatime('picker');

Solution

  • When you call to $('#time').pickatime({...}); you are initializing the component with a set of options. If you want to change some of that options afterwards you have to make use of the API that the component makes available.

    In this case you have to use the method set, you can check it in the documentation.

    So you should call to set whenever you want to change the disabled values likes this:

    timepicker.set('disable', /* your value */);