EasyUI Forum
September 14, 2025, 03:32:05 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: The way I solved datebox() format to return yyyy=mm=dd  (Read 14309 times)
cspeerly
Newbie
*
Posts: 7


View Profile Email
« on: September 04, 2012, 10:03:44 PM »

After hours of messing with this. It was the only way I could get it to work.


see example here when you EDIT OR ADD a record.
http://HomersPHP.tzo.com/jqueryEasyUI/Test-5/index.html

NOTE: have to use the jquery.datebox.js

here is the my code.

Code:
<script type="text/javascript" src="../easyui/plugins/jquery.datebox.js"></script>
<script type="text/javascript">
$('#datebox(').datebox({
    required:true,
});

</head>
...


<!-- *********** HTML  *********** -->
<td><input id="datebox" name="dateentered"></input></td>


Since all my applications use MySQL this works for me
Now edit the jquery.datebox.js

around line 105 tou will see this.

Code:
var y=_1b.getFullYear();
var m=_1b.getMonth()+1;
var d=_1b.getDate();
return y+"/"+m+"/"+d;
},parser:function(s){
var t=Date.parse(s);
if(!isNaN(t)){
return new Date(t);
}else{
return new Date();


change this
return m+"/"+d+"/"+y;
to this
return y+"-"+m+"-"+d;

When entering a date like 2013-1-3 it displays like that on the form
But when you refresh.it appears like this 2013-01-03
I tried to use mm + dd but the it errors out.


Hope this helps
Chuck
« Last Edit: September 04, 2012, 10:20:41 PM by cspeerly » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 04, 2012, 11:42:59 PM »

Please override the 'formatter' and 'parser' function to change the default datebox format, the code looks like this:
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 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();
}
};
Logged
cspeerly
Newbie
*
Posts: 7


View Profile Email
« Reply #2 on: September 05, 2012, 09:08:39 AM »

THANK YOU VERY MUCH, Finally your code worked

Many Thank's
Chuck
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!