3

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?

Eray
  • 7,038
  • 16
  • 70
  • 120
  • 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 Sep 19 '11 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 Sep 19 '11 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 that – Chris Laplante Sep 19 '11 at 23:10
  • No you missunderstood. I don't want to style each letter with an underscore. – Eray Sep 19 '11 at 23:13

1 Answers1

3

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");

fiddle.

Syed Ali hassan
  • 596
  • 4
  • 16
jk.
  • 14,365
  • 4
  • 43
  • 58