html - DatePicker With Today and DateFormat -
i have been trying create jquery ui function datepicker, , after reading forums , snippets out there, realize vast majority of answers have been deprecated and/or removed jquery 1.9.1.
very simply, need have jquery datepicker
display datepicker options of buttons able click on today automatically enter date input field. life of me can't figure out , wanted toss more knowledgeable in jquery/ jquery-ui.
had tried like:
$(function() { $( "#date" ).datepicker(("setdate", new date()){ showbuttonpanel: true, dateformat: 'm-d-yy' }); });
, of course html
<input name="date" id="date" />
the inputed value should in standard usa date format: i.e. 5/1/2013 or 12/31/2099.
as of now, code doesn't select current date, , clicking today select today's date. need automatically populate input field. thank in advance help!
i think problem of (and did i) missunderstand functionality of "today" button. in fact button highlight current date , not select it.
if want behaviour user clicks on today , datepicker selects current date i'd recommend see jsfiddle created.
as not work , did research (working datepicker @ moment too) kindly refer this solution works perfect jquery 1.9.1 , jquery ui 1.9.2.
this code solves issue
$.datepicker._gototoday = function (id) { var target = $(id); var inst = this._getinst(target[0]); if (this._get(inst, 'gotocurrent') && inst.currentday) { inst.selectedday = inst.currentday; inst.drawmonth = inst.selectedmonth = inst.currentmonth; inst.drawyear = inst.selectedyear = inst.currentyear; } else { var date = new date(); inst.selectedday = date.getdate(); inst.drawmonth = inst.selectedmonth = date.getmonth(); inst.drawyear = inst.selectedyear = date.getfullyear(); // below 2 lines new this._setdatedatepicker(target, date); this._selectdate(id, this._getdatedatepicker(target)); } this._notifychange(inst); this._adjustdate(target); }
i hope may :)
edit
to prepopulate input field current date need use setdate method. updated fiddle
$('#datepicker').datepicker('setdate', new date());
Comments
Post a Comment