EasyUI Forum
April 25, 2024, 10:03:01 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED: added new functionality] datebox getValue as Date object  (Read 6548 times)
Coder
Jr. Member
**
Posts: 94


View Profile
« on: December 26, 2019, 10:37:19 AM »

How  get current value from datebox as Date object ?

my formatter is dateFormat(aDate,"dd mmm HH:MM")
and .datebox('getValue') return string in this format ;(
« Last Edit: January 10, 2020, 05:10:38 AM by Coder » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: December 29, 2019, 07:39:47 PM »

Please call this code to convert a string to a Date object.
Code:
var db = $('#db');
var opts = db.datebox('options');
var s = db.datebox('getValue');
var d = opts.parser.call(db[0],s);
console.log(d)
Logged
Coder
Jr. Member
**
Posts: 94


View Profile
« Reply #2 on: December 31, 2019, 11:32:09 AM »

Thnx for Your reply, but:

I use my parser for decode mySQL datetime format

Code:
  function parseMySQLdate(aDate){
var matches = aDate.match(/^\s*(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})\s*$/)
, lDate = new Date()
;

if(matches){
var Y = parseInt(matches[1],10)
,   M = parseInt(matches[2],10) - 1
,   D = parseInt(matches[3],10)
,   H = parseInt(matches[4],10)
,   N = parseInt(matches[5],10)
,   S = parseInt(matches[6],10)
;
            lDate.setDate(D);    
            lDate.setMonth(M);    
            lDate.setFullYear(Y);    
   lDate.setHours(H);
   lDate.setMinutes(N);
   lDate.setSeconds(S);

}

return lDate;
}

so it`s not suitable for...
and  db.datebox('getValue'); return string without year (because my formatter is dateFormat(aDate,"dd mmm HH:MM") )

is there a possibility to store date as Date object in date[time]box inside formatter or inside ('setValue')
and get it as Date object from ('getValue') ?

OR maybe add
 .datetimebox('getDate')
 .datetimebox('setDate',DateObject) ?
« Last Edit: January 02, 2020, 03:40:05 PM by Coder » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: January 04, 2020, 03:23:54 AM »

This is the extended method 'getDate'.
Code:
$.extend($.fn.datebox.methods, {
getDate: function(jq){
var opts = jq.datebox('options');
var s = jq.datebox('getValue');
var d = opts.parser.call(jq[0],s);
return d;
}
})

The live example is available from http://code.reloado.com/oridat4/edit#preview
Logged
Coder
Jr. Member
**
Posts: 94


View Profile
« Reply #4 on: January 07, 2020, 01:43:05 PM »

Thnx for reply, and very interesting code

but:
Code:
$('#db').datebox('setValue','2010-11-01 12:30:00')
var d = $('#db').datebox('getDate');
alert(d.toString());

result is Mon Jun 11 2187 00:00:00

if I change parser for mySQL date parse then it didnt work for "dd mmm HH:MM" format. solve for this is use another parserFunction inside getDate method BUT information about year is lost.

Does it exist access to datebox object from inside formatter? For example for set $(datebox).prop('Date',date)
and extract it from getDate method ( return jq.datebox.prop('Date') ) ?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #5 on: January 09, 2020, 12:40:35 AM »

This is the extended 'setDate' and 'getDate' methods.
Code:
$.extend($.fn.datebox.methods, {
setDate: function(jq, date){
return jq.each(function(){
var opts = $(this).datebox('options');
var value = opts.formatter.call(this, date);
opts.currDate = date;
$(this).datebox('setValue', value);
})
},
getDate: function(jq){
var opts = jq.datebox('options');
if (opts.currDate){
return opts.currDate
}
var s = jq.datebox('getValue');
var d = opts.parser.call(jq[0],s);
return d;
}
})
Logged
Coder
Jr. Member
**
Posts: 94


View Profile
« Reply #6 on: January 09, 2020, 04:20:06 AM »

thnx for road...

may be last question about datebox in this thread ^)

How to owerride or add  changes to currDate variable when date setted with calendar ?
« Last Edit: January 09, 2020, 12:56:57 PM by Coder » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #7 on: January 10, 2020, 02:46:44 AM »

The 'getDate' and 'setDate' methods have been included into the newest version. Please download it from the site.

Here is the live example.
http://code.reloado.com/atorub3/edit#preview
Logged
Coder
Jr. Member
**
Posts: 94


View Profile
« Reply #8 on: January 10, 2020, 05:08:21 AM »

YOU ARE WONDERFUL !   Roll Eyes Roll Eyes Roll Eyes
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!