Although there were so many threads exist in this forum with this discussion, just I am adding a small request to the developer. To use a databox with dd-mm-yyyy format just I have used following parser and formatter, everything is working fine except whenever a blank date is parsed/formatted within this datebox it always puts current date, (It should be, as per my code it is initialized with new Date), but what I require is to initialized with a blank date. The code I have used is :
$.fn.datebox.defaults.formatter = function(date){
if (!date){return ' ';}
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return (d<10?('0'+d):d)+'-'+(m<10?('0'+m):m)+'-'+y;
};
$.fn.datebox.defaults.parser = function(s){
if (!s) return new Date();
var ss = s.split('-');
var d = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var y = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
};
Now what I have done in above code, in parser instead of returning simple new Date() I have used new Date(0,0,0) and in formatter function I have check that
if(date==Date(0,0,0)) {return ' ';}
, but his does not work, instead it returns 31-12-1899 !!! I don't know why.
So please anybody suggest me a way by which I can display a blank date in datebox when it is empty/blank.