-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Cannot disable DatePicker or TimePicker #1113
Comments
You can disable the input for the popup datepicker but I suppose you talk about the inline datepicker & timepicker. Why don't you just hide them? |
Hiding and disabling are two different things. I want to see the set value, but prevent the user from changing that value. |
I know the difference. I was saying that you can just show the value as string in a disabled input or a fancy container and do not show or remove the datepicker control at all. This way you will avoid all the extra elements and watchers that these controls add in your application. Anyway, if you are willing to submit a PR for this then we would be happy to review, but adding all these Leaving open for now in case someone else wants to participate and share thoughts :-) |
The DatePicker and TimePickers may become enabled and disabled at runtime. Swapping to something that looks different between enabled and disabled controls makes the presentation jumpy and confusing. Imagine a checkbox that enables/disables a form section that contains a DatePicker or TimePicker. You would want a consistent layout and look regardless of the control being enabled and disabled. With the DatePicker. I can see the difficulty of disabling the inline calendar, and as a workaround, I can substitute the disabled popout input. However, TimePicker should be easy to disable since it only has 5 buttons and 2 fields. |
Closing because adding all this extra template watchers for the datepikcer & timepicker is going to highly affect their performance. Timepicker does not have (yet) a popup control so there is no way to use the same workaround as you describe for the datepicker. For your situation I would suggest an overlay div with some opacity to indicate the disabled state. |
Its an input field, it should inherit the ability to be disabled... Why can't you bind the event that pops open the control to ng-enabled??? |
One way to do it would be to set date-disabled to "'true'" (all dates unclickable) and show-button-bar to "'false'" (buttons not visible).
|
You can also extend the directive: angular.module('ui.bootstrap.datepicker')
.config(function($provide) {
$provide.decorator('datepickerDirective', function($delegate) {
var directive = $delegate[0];
directive.scope.disabled = '=';
directive.compile = function() {
return function(scope, element, attrs, ctrls) {
directive.link.apply(this, arguments);
var controller = ctrls[0];
var originalDisabled = controller.isDisabled;
controller.isDisabled = function () {
return scope.disabled || (originalDisabled && originalDisabled.apply(this, arguments));
};
scope.$watch('disabled', function () {
controller.refreshView();
});
}
};
return $delegate;
});
}); |
I use ngDisabled attribute in my directive to disable the calendar and it is working smooth |
There does not seem to be a way to disable the DatePicker or TimePicker controls. ng-disable does not seem to be supported.
The text was updated successfully, but these errors were encountered: