Reputation: 481
I have created a function for the jquery date/time picker
function date_picker(t, format) {
format = format || "Y-m-d";
$(t).datetimepicker({
mask:true,
lang:'en',
format:format,
datepicker:true,
timepicker:true,
});
}
I call it on input fields:
<input onclick="date_picker(this, 'Y-m-d');" />
I am having 2 issues, firstly how can I only include datepicker
if the format includes the date and vice versa - how can I only include timepicker
if the format includes time?
The second thing, is if the input is clicked into it shows the mask and then as soon as the input is clicked out of the current date/time will show.
How can it be so if not date/time is selected from the picker, the input stays blank.
Upvotes: 0
Views: 209
Reputation: 434
personally, I would do something like:
<input type="date" value="2016-02-27"><input type="time" value="16:07">
Then you get what you want for free. However, what you are asking for:
psudo code:
<input name="datepicking" onclick="date_picker(this, 'Y-m-d');" />
var booltime = false;
var booldate = false;
if (format == "Y-m-d") booldate = true;
if (format == "Y-m-d H:s") booltime = true;
then
$(t).datetimepicker({
mask:true,
lang:'en',
format:format,
datepicker:booldate,
timepicker:booltime,
});
then you still need to change the value of the input field
Upvotes: 1