EasyUI Forum

General Category => Bug Report => Topic started by: Stefan B. on February 27, 2014, 04:32:18 AM



Title: datebox formater is not called if we set the value with method 'setValue'
Post by: Stefan B. on February 27, 2014, 04:32:18 AM
We use the method 'setValue' for the datebox with the following code
Code:
  $('#svEdCustomerProjectEndDate').datebox('setValue', selectedServer.cusomerProjectEndDate);

And we set the date values in string format or sometimes we would use direct the date in milliseconds!
But on setValue the formatter is not called! Only if we change the date over the box.

If we set the date value as milliseconds the date is shown as the long value string (not formatted).

We override the datebox defaults like the following to handle the value to set with parser and formatter.

Code:
$.fn.datebox.defaults = $.extend({}, $.fn.datebox.defaults, {
formatter : function(date) {
console.log('on date formatter');
var y = date.getFullYear();
var m = date.getMonth() + 1 + '';
if (m.length == 1) {
m = '0' + m;
}
var d = date.getDate() + '';
if (d.length == 1) {
d = '0' + d;
}
return d + '.' + m + '.' + y;
},
parser : function(s) {
if (!s) {
return new Date();
};

if (typeof s === 'string') {
console.log(s + ' >> type is date string ...');
var d = '', m = '', y = '';
if (s.indexOf('.') > 0) {
var ss = s.split('.');
d = parseInt(ss[0], 10);
m = parseInt(ss[1], 10);
y = parseInt(ss[2], 10);
} else if (s.indexOf('/') > 0) {
var ss = s.split('/');
m = parseInt(ss[0], 10);
d = parseInt(ss[1], 10);
y = parseInt(ss[2], 10);
};

if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
return new Date(y, m - 1, d);
} else {
return new Date();
};
} else if (typeof s === 'number') {
    console.log(s + ' >> date in milliseconds');
                     return new Date(s);
};
}
});



Title: Re: datebox formater is not called if we set the value with method 'setValue'
Post by: stworthy on February 27, 2014, 06:44:07 PM
To solve this issue, please download the updated datebox plugin from http://www.jeasyui.com/easyui/plugins/jquery.datebox.js and include it to your page.