1

How can I disable few dates (Ex: one week) on a HTML datepicker? I have an input item like this

<input type="date" id="date01" name="date01" max="2019-12-30">

I know I can use min and max values to limit available time period, but in here, I want to block out some days in the middle. can I do that with plain html date picker? if so, how?

1

1 Answer 1

1

You can't: the HTML5 date input only accepts a lower and upper bound to indicate the allowed date range: you cannot specifically select certain dates that are disabled/non-selectable to the user.

There are two solutions to your approach:

  • Use a combination of client- and server-side validation to let the user know that certain dates are not allowed. This comes at the cost that the user does not know which dates are not allowed when the native date picker is shown in the browser.
  • Alternatively, you can use a third-party library that allows disabling of specific dates.
Sign up to request clarification or add additional context in comments.

3 Comments

cant I even use either JS/jQuery to disable selected dates?
@wydyq You cannot disable it in the native calendar rendered by the browser. You can, however, perform validation using JS to inform the user that certain dates cannot be selected.
thank you for everything. if you can, please help me on how to do that with JS? almost all the thimgs I found are for jquery datepicker. not for html datapicker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.