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
Related
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?
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.
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.
How do I create a date field in angular/html to force the user to input the date in a specific format like MM/yyyy without any validation?
For example: when the user enters the first two digits of month, he should see a slash '/' so that he can enter only 4 more digits for year.
I know it can be done with a simple regex validation, but that will allow the user to enter the date in any format and then validate to show the error.
Instead of fiddling with Javascript and HTML code I would suggest you take a look at some of the baked-in date parser directives offered by angular-bootstrap as a starting point and tweak things from there.
Example 1:
Date parser
Example 2:
Date picker
Example 3:
Date picker with popup
As requested by OP. He is looking at inputting Month/Year only. This example might be more relevant;
Example 4
I'm having trouble finding an elegant way to allow for date/time input in an html form. I am thinking of having drop down menus for year, month, day, hour, minute, second, millisecond that are populated with valid entries only. I could do this by hard coding values for each drop down menu, but I'm thinking there must be a more elegant way to do this, perhaps with some already existing javascript library that I have not found yet. Any tips for getting this done?
edit: Second, and if possible, millisecond precision is needed for what I'm working on.
edit#2: After reading some of the comments, I have come to the realization that it is probably a bad idea to have drop down menus for the large range of values required by hours/minutes/seconds and especially milliseconds. I think will go with having the DatePicker prototype date chooser, along with a simple textfield for time input.
This can be done quite elegantly with a Jquery plug-in called Datepicker
There are many calendars which can do this, with both date and time :
Calendar Date Select
Control.DatePicker (based on PrototypeJS) my favourite, I made an enhanced version, with more features, I can share it
Dynarch calendar but I find it too heavy
and others
I think a very easy way to do this is by using PHP i.e. for making choosing a day and a month:
Use the select command for the form, then insert a PHP line to initiate a for loop. So for the days the loop would go from 1 -> 31 and for the month from 1 -> 12. So instead of hard coding it for all the days months etc, you can neatly fit it into one line of code with a small bit of PHP added.
You could expand on on this plugin since you want second/millisecond
http://www.jnathanson.com/index.cfm?page=jquery/clockpick/ClockPick