xxxxxxxxxx
1
<div id='testDate' class='md-form md-outline input-with-pre-icon datepicker'>
2
<input type='text' id='_testDate' class='form-control w-100'>
3
<label for='_testDate'>Test Date</label>
4
<i class='fas fa-calendar input-prefix'></i>
5
</div>
1
1
xxxxxxxxxx
1
$.fn.disable = function(/* boolean */ isDisabled) {
2
if ($(this).hasClass('datepicker') || $(this).hasClass('timepicker')) {
3
var theLabel = $(this).children('label');
4
var theLabelFor = $(theLabel).attr('for').split(' ');
5
var labelIsDisabled = 'disabled' in theLabelFor ? true : false;
6
7
if (isDisabled) {
8
$(this).children('input').addClass('disabled');
9
$(this).children('i').addClass('disabled');
10
11
if (!labelIsDisabled)
12
$(theLabel).attr('for', $(theLabel).attr('for') + ' disabled');
13
} else {
14
$(this).children('input').removeClass('disabled');
15
$(this).children('i').removeClass('disabled');
16
if (labelIsDisabled) {
17
$(theLabel).removeAttr('for');
18
var newFor = '';
19
theLabelFor.forEach(function(item, index) {
20
if (item !== 'disabled')
21
newFor += newFor.length === 0 ? item : ' ' + item;
22
});
23
$(theLabel).attr('for', newFor);
24
}
25
}
26
}
27
};
28
29
$("#testDate").disable(false);
Console errors: 0