How can I disable only selected dates on html5 datepicker? - javascript

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?

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.

Related

Disable dates using jQuery Datepicker

I understand that we can disable certain dates (Jquery UI datepicker. Disable array of Dates) by manually specifying each date in array however this seems like a messy solution to a problem.
Is there a simpler method of just providing a start and end date of a period in which dates should be disabled? i.e. 07/07/2020 to 07/08/2020 rather than specifying each date between these?

HTML: Input type date and range of months

I'm trying to make an HTML form with input type="date" which will be a range of months but not years. For example I need the user to select a date with a range from March to October, but with all available years (2019, 2020, 2021...).
I know about option of attributes min and max but we must fill the entire specific date and I only need a range of months.
CODE of min and max:
<input type="date" min="2019-03-01" max="2019-10-31">
Is there any option to do this with clear HTML or must we use JavaScript?
Unfortunately, there is no way to eliminate the 'year' portion of the HTML date input, which makes some sense given that it has such wildly different implementations on different platforms.
JS will let you build what you want, but it will be more difficult to ensure cross-platform reliability. Here's one option, you can use a date input but restrict it and then strip the response with JS, though that does not actually hide the option to change the year.
How to hide the year part in Html <input type="date"> calendar panel?
Here's a similar SO answer that could lead you down a path to manipulate jquery's datepicker to do what you want:
https://stackoverflow.com/a/10243049/1650488
Ultimately, there are a lot of benefits with sticking to the native HTML elements instead of rolling your own solution, so personally I'd look at the workflow and try to make it make sense with the native datepicker.
If the native element really doesn't work, It might make sense to build your own input such as selecting the date and month range separately, but then you could run in to troubles with differing lengths of months and it will be hard to manage accessibility devices such as screen readers.

Jquery input mask to input date range

I am making a web app which should accept a specific interval that is added to the target date to check if the request is expired. So I need an input with formatting: months:days:hours
Where months is limited to 12, days to 31, and hours to 24. I tried to use jQuery inputmask plugin
I made like this:
https://jsfiddle.net/qahxvspb/2/
But it doesn't work for some reason, I put a mask like this:
mask: "mm-dd-hh"
But in the input I get weird stuff, there is still placeholder mm-dd-yyyy, and I only can input year into it.
So 2 questions:
How to make a correct mask?
How can I make allow zero month in the mask? So, basically, it would be optional for the range, if I want I would just put 0 into month, check that on server, and create a range only from days and hours.
Javascript Date makes my head hurt because of things like what you are trying to do
I use a library called moment,which is available as a cdn or npm package
It can create input patterns like the one you have, do arithmetic on dates and then convert to the time format you want, even Javascript Date

From html input="date" to html select drop down format

Is it possible to convert html tag/format <input type="date"> to html tag/format <select><option></option></select> ?
I just wanted to make an input type date to a select drop down format.
For example:
From
Date of Birth - input type date
To
Date of Birth - select drop down option
Actually, I don't want to separate the date of birth values into three. But instead, make a better solution wherein I can transform the input date into a select drop down one.
Anyone who can help me with this one? Thank you.
You may use jQuery plugin to showcase a datepicker like the one below:
https://plugins.jquery.com/datetimepicker/
You can easily find many other jQuery plugins for the same.
If you wish to play around with its UI, you may use jQuery UI built-in themes or write some CSS on your own.
Depending on the browser to open dialog. and also input type=date not support in every browser.

Date Range functionality for Datebox

I am using Datebox widget and want to limit the dates from which the user can choose.
eg. Only dates between 2013-Jan-02 and 2013-Jan-25 should be enabled, rest disabled.
How do I provide these values programatically ? Passing it in JSON is not working for me.
$('#dateInput').datebox({"mode": "calbox", 'min':"2013-01-02", 'max':"2013-01-25"});
Please let me know the syntax to pass the date range parameters.
I dont know whether it is possible in Datebox widget. But if you pick Jquery UI datepicker, it has this option.
Have a look at this if you are interested
http://jqueryui.com/datepicker/#min-max

Categories