javascript - jQuery Datepicker Show Current Date -


datepicker script:

$(function(){            $( "#task_start_date").datepicker({          dateformat: 'dd-m-yy',          showon: 'button',          buttonimage :image_us,          buttonimageonly: true         }); 

html input:

<input type="text" class="form-control validate[required,custom[date]]" name="task_start_date" id="task_start_date" /> 

when clicked in calendar icon, dateformat: 'dd-m-yy', outputs 27-nov-2014 , shows current date highlighted,

but dateformat: 'dd-m-y', outputs 01-mar-12 , shows 01-mar-12 highlighted instead of current.

i using jquery validation engine validate date format. below fiddle works fine not expected date format.

js fiddle: fiddle

thanks.

i saw js fiddle. think, have mistake on regexp result null.

i tried change regexp.

new regexp(/([12]\d|0[1-9]|3[0-1])-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)-(\d{4})/);

change to

new regexp(/([12]\d|0[1-9]|3[0-1])-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)-(\d{2,4})/);

and change

var isok = (d.getfullyear() == year && d.getmonth() == months.indexof(month) && d.getdate() == day);

to

var isok = (d.getyear() == (year).slice(-2) && d.getmonth() == months.indexof(month) && d.getdate() == day);

below full code. second changed version.

$( "#task_start_date").datepicker({     monthnamesshort: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"],     dateformat: 'dd-m-y',     defaultdate: '18-nov-14',     onclose: function (date) {         var pattern = new regexp(/([12]\d|0[1-9]|3[0-1])-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)-(\d{2,4})/);         var match = pattern.exec(date);         if (match == null)              return false;          var months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]         var year = match[3];         var month = match[2];         var day = match[1];          var d = new date(year, months.indexof(month), day);         var isok = (d.getyear() == (year).slice(-2) && d.getmonth() == months.indexof(month) && d.getdate() == day);                 alert(isok);    } }); $("#task_start_date").datepicker( "setdate", new date()); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -