This is a migrated thread and some comments may be shown as answers.

How to disable/enable DateTimePicker control?

1 Answer 1536 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chunsheng
Top achievements
Rank 1
Chunsheng asked on 20 Dec 2011, 05:07 PM
Hi All

Could you please help me about how to disable/enable a Telerik MVC DateTimePicker in javascript. I am using:

$("#Name").attr('disable', 'disable');

It works for a general Html control; but it can not disable a DateTimePicker.

Thanks very much in advance.

Chunsheng

1 Answer, 1 is accepted

Sort by
0
John DeVight
Top achievements
Rank 1
answered on 16 Jan 2012, 05:27 PM
Hi Chunsheng,

When the DatePicker is rendered, it is made up of several HTML elements and looks like this:

<div class="t-widget t-datepicker">
    <div class="t-picker-wrap">
        <input type="text" value="11/30/1973" name="Birthday" id="Birthday" data-val-required="The Birthday field is required." data-val="true" class="t-input" autocomplete="off" disable="disabled">
        <span class="t-select">
            <span title="Open the calendar" class="t-icon t-icon-calendar" style="visibility: visible;">Open the calendar</span>
        </span>
    </div>
</div>


If I were disabling the DatePicker, I would probably disable the input field and also hide the calendar icon like this:

$('#Birthday').attr('disabled',true)
    .next(
'span.t-select')
        .children(
'span.t-icon-calendar').css('visibility','hidden')

To enable it again, I would do this:

$('#Birthday').removeAttr('disabled',true)
    .next(
'span.t-select')
        .children(
'span.t-icon-calendar').css('visibility','visible')

Regards,

John DeVight
Tags
Date/Time Pickers
Asked by
Chunsheng
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
Share this question
or