EasyUI Forum
September 13, 2025, 06:48:50 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: datebox formater is not called if we set the value with method 'setValue'  (Read 10929 times)
Stefan B.
Full Member
***
Posts: 152


Software Architekt


View Profile Email
« 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);
};
}
});

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!