Re-initialize or destroy Bootstrap datepicker dynamically

前端 未结 5 1916
别跟我提以往
别跟我提以往 2021-02-05 06:19

Is there a way to destroy the Bootstrap datepicker dynamically updating its options like format, beforeShowDay, etc.? I know that the jQuery UI datepicker has a destroy method b

相关标签:
5条回答
  • 2021-02-05 06:48

    You can Use:

    $('#element_id').datepicker('destroy');

    I called this just outside my ajax call. My ajax call was creating the datepicker dynamically. After the call was made I destroyed the object.

    Like below:

    $.ajax({ url: 'my_ business_functions.php',
         data: {func_call: 'my_method_name', my_parameter: my_parameters},
         type: 'post',
         success: function(output) {
             //all my stuffs here
            $('#element_id').val(datepicker_value);
            }
        });
        $('#element_id').datepicker('destroy');
    

    This served my purpose.

    0 讨论(0)
  • 2021-02-05 07:04
    $('.datepicker').datepicker('remove');
    

    Make sure you have your date picker object in DOM before removing it. Without removing you can hide the calendar and change the format of date and update it .

    $('.datepicker').datepicker('update');
    
    0 讨论(0)
  • 2021-02-05 07:11

    I actually found it more to just remove the element's ID, clone it, and add the ID back in.

    0 讨论(0)
  • 2021-02-05 07:12

    Propably you are using datepicker with input btn group, I mean you with a date icon button. So, you should not choose just input element when you want to destroy it and reinit. You should select div has "date-picker", then remove and init again.

    0 讨论(0)
  • 2021-02-05 07:13
    forceParse: 1
    

    In your options. It will parse the input date field value every time.

    0 讨论(0)
提交回复
热议问题