Topic: validate date that is not greater than today. (datepicker)

yeisonvelez11 free asked 5 years ago


I want to do this dynamic, therefore I can not put fixed information. What is the best way? Is there any method or something I can do to keep it from going over the start date?

disableUntil: {year: 2018, month: 10, day: 1},

disableSince: {year: 2018, month: 10, day: 31},

disableDays: [{year: 2018, month: 10, day: 3}],

Arkadiusz Idzikowski staff answered 5 years ago


Dear yeisonvelez11,

Here is an example:

disableDates() {

const date = newDate();

const year = date.getUTCFullYear();

const month = date.getUTCMonth() +1;

const day = date.getUTCDate() +1;

const tomorrowDate = { year, month, day };

this.myDatePickerOptions.disableSince = tomorrowDate;

}
I hope this is what you needed.
 
Regards,
Arek

Arkadiusz Idzikowski staff answered 5 years ago


Dear yeisonvelez11,

Could you provide more information about the problem and expected behavior? If you need to update those options dynamically you need to pass the copy of the options object to the date picker input in order to trigger Angular change detection. Here is an example:

this.myDatePickerOptions = {...this.myDatePickerOptions, disableUntil: {year: 2018, month: 10, day: 10 } };
 
Regards,
Arek

yeisonvelez11 free commented 5 years ago

@Arkadiusz Idzikowski  thanks,

 

It is not a problem as such. It's something I do not know how to do. I simply want to validate that the date you select is not from a later date. For example today is 2018/12/13, should allow me the option to select a later date. and this validation I need to be dynamic, that is to say that it never allows me to choose a date later than the current day.

disableUntil: {year: currentyear, month: currentmonth, day: currentday}

 



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 7.0.0
  • Device: web
  • Browser: chrome
  • OS: windows
  • Provided sample code: Yes
  • Provided link: No