EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Coder on January 21, 2020, 05:04:19 PM



Title: datebox calendar error
Post by: Coder on January 21, 2020, 05:04:19 PM
datebox:
Code:
 , formatter:fmtShrtDate
 , parser:parseMySQLDate

Code:
function fmtShrtDate(aDate){ // DateObject -> "DD MMM"
 return dateFormat(aDate,"dd mmm")
};
function parseMySQLDate(sqlDate){ // "YYYY-MM-DD[[ HH:MM]:SS]" -> DateObject
 return new Date().parseMySQL( sqlDate + ((sqlDate.length==16)?':00':((sqlDate.length==10)?' 00:00:00':'')) )
};


why calendar use datebox.parse (setValue ?) to set date ?
May be it use newest :) datebox('setDate') ?  ;)

(https://www.jeasyui.com/forum/index.php?action=dlattach;topic=8211.0;attach=2041;image)

http://code.reloado.com/atorub3/4/edit#preview


Title: Re: datebox calendar error
Post by: jarry on January 23, 2020, 06:53:33 AM
Please look at this updated example http://code.reloado.com/atorub3/6/edit#preview. It works fine.


Title: Re: datebox calendar error
Post by: Coder on January 23, 2020, 02:01:48 PM
thnx for answer

setValue - didnt work!

http://code.reloado.com/atorub3/7/edit#preview


Title: Re: datebox calendar error
Post by: jarry on January 23, 2020, 09:48:15 PM
Your function should be defined as:
Code:
function setValue(){
  var mySQLdate = "1999-01-02 03:04:00";
  var date = new Date().parseMySQL(mySQLdate);
  var m = date.getMonth();
  var d = date.getDate();
  var v = (d<10?('0'+d):d)+' '+monthNames[m];
  $('#dt').datebox('setValue', v);
}

This example works fine.
http://code.reloado.com/atorub3/8/edit#preview


Title: Re: datebox calendar error
Post by: Coder on January 28, 2020, 06:44:53 PM
Thanx for answer, but:

Code:
function setValue(){
  var mySQLdate = "1999-01-02 03:04:00";
  var date = new Date().parseMySQL(mySQLdate);
  var m = date.getMonth();
  var d = date.getDate();
  var v = (d<10?('0'+d):d)+' '+monthNames[m];
  $('#dt').datebox('setValue', v);
 alert($('#dt').datebox('getDate'))
}

Thu Jan 02 2020 00:00:00  =/= "1999-01-02 03:04:00"


and didnt work setDate|getDate when parser and formatter have different format

How do datetime widget to store date via parser (setValue) and setDate as date object in internal widget variable?
and getDate is return dateObject from internal variable ?


Title: Re: datebox calendar error
Post by: Coder on January 28, 2020, 07:37:16 PM
may be
datetime('setDate',DateObject) -> set internal aDate variable and setText via formatter(dateObject)
datetime('getDate') -> get internal aDate variable

datetime('setValue',text) -> set internal aDate variable via parser(aText) and setText via formatter(dateObject)
datetime('getValue') -> getText

and Calendar -> (setDate, DateObject) (-> set internal aDate variable and setText via formatter(dateObject) )



now when I do  ('SetDate',DateObject) // new Date().mySQLparser('1999-01-02 03:04:00')
widget do internal call ->formatter      // 02 Jan 03:04
and then -> parse from TextBox :(      // error because my parser NOT FOR format 'DD mmm HH:MM'
                                                        // and if I do formatter for 'DD mmm HH:MM'  in result  year  == 2020 !


Title: Re: datebox calendar error
Post by: jarry on January 30, 2020, 04:16:26 AM
The datebox doesn't store the time(hour,minute and second) information. Please use the datetimebox instead.


Title: Re: datebox calendar error
Post by: Coder on January 30, 2020, 05:59:08 PM
Thnx 4 rply!

"The datebox doesn't store " oh, of course I mean datetimebox!

Sutuation with datetimebox the same :(

http://code.reloado.com/atorub3/14/edit#preview


Title: Re: datebox calendar error
Post by: jarry on January 31, 2020, 07:11:04 PM
Your 'pad' function should be defined as:
Code:
pad = function(aN){return (parseInt(aN,10)<10?('0'+parseInt(aN,10)):parseInt(aN,10))}  

This example works fine.
http://code.reloado.com/atorub3/15/edit#preview


Title: Re: datebox calendar error
Post by: Coder on February 02, 2020, 06:08:27 PM
Thnx 4 reply!

in Your version 15 :

'formatter' do convert from dateObject to String "DD MMM HH:MM"
and
'parser' do convert from String  "DD MMM HH:MM" to DateObject

and all work fine!

in my version

'formatter' do convert from dateObject to String "DD MMM HH:MM"
and
'parser' do convert from String  "YYYY-MM-DD HH:MM:SS" to DateObject
( editable: false - so user cant edit value in box, only choose datetime from calendar )

and when I do ('setDate',DateObject) the error in parser !
I dont understand why setDate use 'parser'

setDate (maybe) can do:  set local Date variable and use only formatter to set visible value! why it use 'parser' ?
and
calendar (maybe) can do only ('setDate',DateObject)
 // but now it use formatter for generate correct visible string AND then it use parser to parse this generated string to dateObject !!


Title: Re: datebox calendar error
Post by: jarry on February 03, 2020, 08:15:05 PM
The 'parser' function parse the inputing text that is formatted by the 'formatter' function. i.e. the inputing text should stay in the same format as the 'formatter' function does. If you format it as 'DD MMM HH:MM', you should parse it from 'DD MMM HH:MM' format.


Title: Re: datebox calendar error
Post by: Coder on February 04, 2020, 07:23:17 PM
Thnx for answer.

ok, understand about format and parser|formatter.

Can be ('setDate',DateObject) use only formatter to set formatted text without use parser ?


Title: Re: datebox calendar error
Post by: jarry on February 06, 2020, 04:13:27 AM
You can try to override the 'setDate' method according to your logic.
Code:
$.extend($.fn.datetimebox.methods, {
setDate: function(jq, date){
return jq.each(function(){
var opts = $(this).datetimebox('options');
$(this).datetimebox('calendar').calendar('moveTo', date);
// set the value here
});
}
})


Title: Re: datebox calendar error
Post by: Coder on February 06, 2020, 06:40:32 PM
Thnx 4 answer, and your patience :)

why calendar use parser after user choose ?
why setDate use parser after use formatter ?

http://code.reloado.com/atorub3/20/edit#source

if defined only formatter - datetimebox didnt work!

my English level is poor (this language is not my native)

I want to give advice to change internal actions of CalendarChoose and setDate to did not parse (use 'parser') of the text which the this functions just now generated.



Title: Re: datebox calendar error
Post by: jarry on February 07, 2020, 12:59:44 AM
The 'parser' function must be defined to convert the inputing string to a valid Date object. Define both the 'formatter' and 'parser' to let them work normally according to your logic. Please look at this updated example.

http://code.reloado.com/atorub3/21/edit#preview


Title: Re: datebox calendar error
Post by: Coder on February 07, 2020, 06:12:10 PM
Thnx 4 reply!

My advice:

datebox.js
Code:
// ...
// line 62
$.extend(state.calendar.calendar('options'), {
fit:true,
border:false,
onSelect:function(date){
var target = this.target;
var opts = $(target).datebox('options');
var calendar = $(target).datebox('calendar'); // +
opts.onSelect.call(target, date);
calendar.calendar('moveTo', date); // +
setText(target); // +
// - setValue(target, opts.formatter.call(target, date));
$(target).combo('hidePanel');
}
});
// ...
// line 128
function doEnter(target){
var state = $.data(target, 'datebox');
var opts = state.options;
var current = state.calendar.calendar('options').current;
if (current){
setText(target); // +
$(target).combo('hidePanel');
// - setValue(target, opts.formatter.call(target, current));
}
}

function setValue(target, value, remainText){
var state = $.data(target, 'datebox');
var opts = state.options;
var calendar = state.calendar;
calendar.calendar('moveTo', opts.parser.call(target, value));
if (remainText){
$(target).combo('setValue', value);
} else {
setText(target); // +
// - if (value){
// - value = opts.formatter.call(target, calendar.calendar('options').current);
// - }
// - $(target).combo('setText', value).combo('setValue', value);
}
}

function setText(target){  // +
var state = $.data(target, 'datebox')
, opts = state.options
, calendar = state.calendar
, value = opts.formatter.call(target, calendar.calendar('options').current)
;
$(target).combo('setText', value).combo('setValue', value);
}
}


// ...
// line 224
setDate: function(jq, date){
return jq.each(function(){
var opts = $(this).datebox('options');
$(this).datebox('calendar').calendar('moveTo', date);
// - setValue(this, date ? opts.formatter.call(this, date) : '');
setText(this); // +
});
},