greatCodeIdeas / md-date-range-picker

Angular Material Date Range Picker Service/Directive
MIT License
62 stars 40 forks source link

Can we disable future dates from the controller? #36

Closed vishnu-vv closed 6 years ago

vishnu-vv commented 6 years ago

Like this

$rootScope.selectedRange = {

     selectedTemplate:'L30D',
      selectedTemplateName: 'Last 30 Days',
      dateStart: new Date(tempDate),
      dateEnd: new Date(),
      showTemplate: true,
      fullscreen: true,
      firstDayOfWeek: 0,
      isDisabledDate: '$rootScope.isFutureDate($date)'

};

$rootScope.isFutureDate = function ($date) {

      return $date.getTime() < new Date().getTime();

};
roelbarreto commented 6 years ago
$rootScope.selectedRange = {

     selectedTemplate:'L30D',
      selectedTemplateName: 'Last 30 Days',
      dateStart: new Date(tempDate),
      dateEnd: new Date(),
      showTemplate: true,
      fullscreen: true,
      firstDayOfWeek: 0,
      isDisabledDate: $rootScope.isFutureDate($date)

};

$rootScope.isFutureDate = function ($date) {

      return $date.getTime() < new Date().getTime();

};
vishnu-vv commented 6 years ago

@ipiz But it is causing error $date is not defined Thanks for your quick response

roelbarreto commented 6 years ago

Sorry this should be the right one, just pass the reference to the function not the function call

$rootScope.isFutureDate = function ($date) {

      return $date.getTime() < new Date().getTime();

};
$rootScope.selectedRange = {

     selectedTemplate:'L30D',
      selectedTemplateName: 'Last 30 Days',
      dateStart: new Date(tempDate),
      dateEnd: new Date(),
      showTemplate: true,
      fullscreen: true,
      firstDayOfWeek: 0,
      isDisabledDate: $rootScope.isFutureDate,

};
vishnu-vv commented 6 years ago

@ipiz Let me try that, Thanks a lot yaar. 👍

vishnu-vv commented 6 years ago

@ipiz Actually, what is this property isDisabledDate meant for, i thought it was meant for disabling the future dates in the date-range-picker. But trying the options you gave me, the future dates are not disabled.

vishnu-vv commented 6 years ago

@ipiz Any update ?

roelbarreto commented 6 years ago

It disable dates when your callback returns true you can check some example at the demo site https://ipiz.herokuapp.com/md-date-range-picker-demo/index.html

vishnu-vv commented 6 years ago
$rootScope.isFutureDate = function ($date) {
      return $date.getTime() < new Date().getTime();
};

$rootScope.selectedRange = {
      selectedTemplate:'L30D',
      selectedTemplateName: 'Last 30 Days',
      dateStart: new Date(tempDate),
      dateEnd: new Date(),
      showTemplate: true,
      fullscreen: true,
      firstDayOfWeek: 0,
      isDisabledDate: $rootScope.isFutureDate,
};

This did the fix for me. Thanks brother. 👍 PS: define the function $rootScope.isFutureDate before $rootScope.selectedRange