Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularUI Datepicker dynamic date disabling

I am using the AngularUI datepicker.

I have two datepickers that influence each other. One is for example a "start date" and the other is an "end date". Instead of creating validation for both datepickers, I want to eliminate the option of having invalid dates (i.e. end date earlier than the start date and vice versa).

Is there a way to re-trigger the date-disabled attribute on select of a date? (re-trigger the date-disabled of the OTHER datepicker)

My plunkr: I have a start and end date, as you can see when you open each date picker, you cannot pick a start date higher than the end date and vice versa. However if I change my start date to 11/21, I want the end date's datepicker to update so that the 11/20 is no longer clickable. Is there any way to do this?

http://plnkr.co/edit/TgisJnSwQItDeCuIReLL?p=preview

like image 461
changus Avatar asked Nov 27 '13 01:11

changus


People also ask

How to disable past and future dates in Angular Material datepicker calendar?

This page will provide how to disable past and future dates in Angular Material Datepicker calendar. We can disable dates using following Datepicker input text properties. 1. Using min and max properties 2. Using matDatepickerFilter property. The min configures minimum date to be selected and max configures maximum date to be selected.

How do I disable the selection of specified dates in datepicker?

The DatePicker allows you to disable the selection of specified dates by providing a disabledDates value to the component. The DatePicker supports the following approaches for disabling dates: Using a function — The format for this input is (date: Date) => boolean. The approach disables each date for which the provided function returns true.

How do I make the datepicker read only from the popup calendar?

The DatePicker input doesn't prevent the user from entering dates, which are marked as disabled, with typing. Set the readOnlyInput property of the DatePicker to true, allowing in this way the user to choose a date only from the popup Calendar ( see example ).

What is the difference between dateref and datepicker?

Notice the local variable for input field is named dateRef and local variable for date-picker is named datePicker and they are not same. Show activity on this post. I was a similar problem after enabling ivy compiler in a project with angular 9 with material.


2 Answers

It is possible to do this using min and max attributes in combination with watching pickers' values. Look at http://plnkr.co/edit/W5pb1boMLOHZFnWkMU8o?p=preview

like image 88
zergius Avatar answered Sep 20 '22 06:09

zergius


You really don't need all the javascript. here is a fork of the previous solution.

http://plnkr.co/edit/kXkzCeBTlxOpOyZKfTiN

if you have two inputs such as

         <input id="getTSStartDateInput" ng-model="StartDate" type="text" class="form-control ng-pristine ng-valid ng-valid-required" datepicker-popup="dd MMM yyyy" required="required" ng-required="true"/>  
           <input id="getTSEndDateInput" ng-model="EndDate" min="StartDate" type="text" class="form-control ng-pristine ng-valid ng-valid-required" datepicker-popup="dd MMM yyyy" required="required" ng-required="true"/>

it will automatically work and disable any end date that is before the start date notice the ng-model="EndDate" min="StartDate", that is all you need.

like image 26
Abdullah Choudhury Avatar answered Sep 20 '22 06:09

Abdullah Choudhury