How to disable Bootstrap DatePicker

馋奶兔 提交于 2019-12-05 09:00:33

By the comments you gave this looks like a suitable solution for you

$(document).ready(function() {
    $('#state').on('change', function() {
       if ($(this).val() == 'on') {
           $('#dateRangePicker').datepicker({
                format: 'dd/mm/yyyy',
                startDate: '01/01/2010',
                endDate: '12/30/2020',
                autoclose: true,
                language: 'da',
                enableOnReadonly: false
            });
            $('#dateRangePicker > .form-control').prop('disabled', false);
        } else {
            $('#dateRangePicker').datepicker('remove');
            $('#dateRangePicker > .form-control').prop('disabled', true);
        }
    });
    $('#dateRangePicker > .form-control').prop('disabled', true);
});

See this jsfiddle for a working example!

You can control the button click separately to the datepicker as long as the datepicker initialization targets the input.

Target the input #kalib_dato with .datepicker() instead of the input-group#dateRangePicker.

Add an id to the button span... such as 'kalib_spano' then the button can conditionally show the datepicker.

$("#kalib_spano").click(function () {
    if (!someDisabledCondition) {
        // trigger the datepicker
        $("#kalib_dato").datepicker("show");
    }
});

If someone else finds this that is using the angular plugin ng2-datetime which uses bootstrap-timepicker and bootstrap-datepicker under the hood, I was able to tweak acrobat's answer for this case. I had to use a different selector, but otherwise acrobat's solution was spot on for my case. My class custom-date-time-picker is applied at the component level for the plugin. I am only using the time-picker part of the plugin, having disabled the datepicker.

<datetime class="custom-date-time-picker" [datepicker]="false" [timepicker]="timePickerOptions"></datetime>

$('.custom-date-time-picker .form-control').prop('disabled', true); $('.custom-date-time-picker .form-control').prop('disabled', false);

Try this code

$("#YourDateID").prop('disabled', true);

Don't initialize datepicker in javascript. If you dont need the datepicker.

Just use below HTML code.

<div class="input-group input-append date" id="dateRangePicker">
<input type="text" class="form-control" name="date" id="kalib_dato" disabled readonly />
<span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!