EasyUI Forum
October 10, 2024, 10:34:46 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: Using easyloader and setting defaults.formatter to datebox  (Read 4019 times)
WizPS
Jr. Member
**
Posts: 67


View Profile
« on: February 04, 2020, 06:39:10 PM »

Hi, I'm using easyloader and wants to extend datebox defaults.formatter with the following code
Code:
$.fn.datebox.defaults.formatter = function (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);
};
$.fn.datebox.defaults.parser = function (s) {
if (!s) return new Date();
var ss = s.split('-');
var d = parseInt(ss[2], 10);
var m = parseInt(ss[1], 10);
var y = parseInt(ss[0], 10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
return new Date(y, m - 1, d);
} else {
return new Date();
}
};
Can I put this into the $.extend(easyloader.modules, {})?
How should that look?
Please advice.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2274


View Profile Email
« Reply #1 on: February 06, 2020, 04:46:17 AM »

You just need to set your locale language.
Code:
<script type="text/javascript">
easyloader.locale = 'en';
</script>
Logged
WizPS
Jr. Member
**
Posts: 67


View Profile
« Reply #2 on: February 06, 2020, 11:41:17 AM »

The suggested code gives the following date format: ss/mm/yyyy while I am after yyyy-mm-dd. The code I supplied gives the format attached. No language selection gives me this swedish date format, not 'se_SW' either. Pls advice.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2274


View Profile Email
« Reply #3 on: February 06, 2020, 11:51:37 PM »

Build a simple locale file named 'easyui-lang-se_SW.js' and save it to the 'locale' directory, it looks line this.
Code:
if ($.fn.datebox){
$.fn.datebox.defaults.formatter = function(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);
};
$.fn.datebox.defaults.parser = function(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();
}
};
}

Register this locale file in the 'easyloader'.
Code:
<script type="text/javascript">
$.extend(easyloader.locales, {
'se_SW': 'easyui-lang-se_SW.js'
});
easyloader.locale = 'se_SW';
</script>
Logged
WizPS
Jr. Member
**
Posts: 67


View Profile
« Reply #4 on: February 07, 2020, 05:00:59 PM »

Perfect, that works very good thanks.
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!