EasyUI Forum

General Category => General Discussion => Topic started by: julioc on March 23, 2015, 10:06:30 AM



Title: [SOLVED] Error with Datebox
Post by: julioc on March 23, 2015, 10:06:30 AM
Hello everyone. I have a problem adding a datebox format, using the version 1.3.5 I worked perfectly, but 1.4.2 does not work, do not know if it's a bug in the code.

In the demo that comes with jeasyui put this

Code:
function myformatter(date){
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    var d = date.getDate();
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
    if (!s) return new Date();
    var ss = (s.split('-'));
    var y = parseInt(ss[0],10);
    var m = parseInt(ss[1],10);
    var d = parseInt(ss[2],10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
        return new Date(y,m-1,d);
    } else {
        return new Date();
    }
}

I use this

Code:
function myformatter(date){
            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;
        }

        function myparser(s){
            if (!s) return new Date();
            var ss = (s.split('-'));
            var y = parseInt(ss[0],10);
            var m = parseInt(ss[1],10);
            var d = parseInt(ss[2],10);
            if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
                return new Date(y,m-1,d);
            } else {
                return new Date();
            }
        }

and does not work, it always shows me the current date using my format.  :(


Title: Re: Error with Datebox
Post by: stworthy on March 23, 2015, 05:50:00 PM
You must custom the 'formatter' and 'parser' functions together to let the datebox work correctly.
Code:
function myformatter(date){
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;
}
function myparser(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();
}
}


Title: Re: Error with Datebox
Post by: julioc on March 23, 2015, 06:49:28 PM
Mmm ... I did not notice, the order of that. My mistake.

Thank You.  :)