First of all check live example . There is a mask for dates on text box. Also there is a jQueryUI datepicker. They are working very well but when i choose a date with datepicker, text box's mask is disappearing. I want to keep it. Any ideas?
-
It works fine for me, Google Chrome on Windows 7. The underlining (mask effect) is lost when a date is entered, but that is normal. Unless you want to keep the underlining?Chris Laplante– Chris Laplante2011-09-19 23:05:37 +00:00Commented Sep 19, 2011 at 23:05
-
I want to keep them . Actually i want to turn it to (for example) 2011-09-19 00:00 . So visitor will be noticed, there is a time (00:00) and it can be changed.Eray– Eray2011-09-19 23:07:22 +00:00Commented Sep 19, 2011 at 23:07
-
The problem is that the underscore can't exist in the same place as the letter. Unless there is a way to style each individual letter with underlining. Not sure about thatChris Laplante– Chris Laplante2011-09-19 23:10:59 +00:00Commented Sep 19, 2011 at 23:10
-
No you missunderstood. I don't want to style each letter with an underscore.Eray– Eray2011-09-19 23:13:01 +00:00Commented Sep 19, 2011 at 23:13
Add a comment
|
1 Answer
I used this post. To create this fiddle.
You can adjust the javascript to default to 00:00 if you don't want the current time as the default.
date_obj = new Date();
date_obj_hours = date_obj.getHours();
date_obj_mins = date_obj.getMinutes();
if (date_obj_mins < 10) { date_obj_mins = "0" + date_obj_mins; }
if (date_obj_hours < 10) {date_obj_hours = "0" + date_obj_hours;}
date_obj_time = "'"+date_obj_hours+":"+date_obj_mins+"'";
$( ".datepicker" ).datepicker({ dateFormat: 'yy-mm-dd ' + date_obj_time });
$(".datepicker").mask("9999-99-99 99:99");
Thought I would add that this could be shortened to:
date_obj = new Date();
date_obj_hours = date_obj.getHours() < 10 ? "0" + date_obj.getHours() : date_obj.getHours();
date_obj_mins = date_obj.getMinutes() < 10 ? "0" + date_obj.getMinutes() : date_obj.getMinutes();
date_obj_time = "'" + date_obj_hours + ":" + date_obj_mins + "'";
$(".datepicker").datepicker({ dateFormat: 'yy-mm-dd ' + date_obj_time });
$(".datepicker").mask("9999-99-99 99:99");