1

I want to disable certain days from a datepicker like weekends. I've read that it's possible using Jquery but I couldn't find any documentation related to LWC.

Thanks, Kamal

1
  • this will be tricky because of the shadow dom, I would suggest to either create your own component or create some custom validation when the weekend is selected rather than disabling it
    – Damecek
    Commented Oct 26, 2022 at 15:05

1 Answer 1

1

Realistically, you can only choose min/max dates with the default picker, and even then, it doesn't restrict selection, it simply shows an error. Instead, you could use an onchange handler to check if the selected date is a weekend, and use setCustomValidity to indicate an error if a weekend is selected.

handleDateInputChange(event) {
  const date = new Date(event.target.value);
  const dayOfWeek = date.getDay();
  if(dayOfWeek === 0 || dayOfWeek === 6) {
    event.target.setCustomValidity('You cannot select a weekend date.');
  } else {
    event.target.setCustomValidity('');
  }
  event.target.reportValidity();
}
2
  • Thanks for the answer but I don't need validation here. I want to disable the dates is there any other way to achieve this?
    – Kamal
    Commented Nov 1, 2022 at 3:39
  • @Kamal Not in native components. You'll have to write something custom.
    – sfdcfox
    Commented Nov 1, 2022 at 5:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .