on 2018 Nov 27 2:10 PM
I am using Datebox in my zkoss application for getting a date from the user. Currently, I am having a requirement that when user clicks on the datebox for the first time (please note that initially no value is set to the datebox), the datebox pop up which opens up should have the default time set to '00:00' instead of the current time. I could not find any API in the 'org.zkoss.zul.Datebox' class which could be used for modifying the default time of its timebox component. I tried customizing the zk datebox too but in vain, absolutely clueless of where and how to insert an API to change the initial time of the associated timebox. Kindly help.
Request clarification before answering.
Hi Bijan,
You might have to write/update custom js to set the time as 00:00. Currently it is done as below in web/webroot/cockpit/commonCSA.zul ///////////////////////////////////// // ZK Datebox fix
zk.parseDate = function (txt, fmt, strict) {
if (!fmt) fmt = "yyyy/MM/dd";
var val = new Date(),
y = val.getFullYear(),
m = val.getMonth(),
d = val.getDate(),
hr = val.getHours(),
min = val.getMinutes(),
sec = val.getSeconds(),
aa = fmt.indexOf('a'),
hh = fmt.indexOf('h'),
KK = fmt.indexOf('K'),
hasAM = aa > -1,
hasHour1 = hasAM ? hh > -1 || KK > -1 : false,
isAM;
var ts = [], mindex = fmt.indexOf("MMM"), aindex = fmt.indexOf("a"), ary = [],
mmindex = mindex + 3;
for (var i = 0, j = txt.length; i < j; i++) {
var c = txt.charAt(i);
var beforeC = txt.charAt(i-1);
var afterC = txt.charAt(i+1);
var dot = true;
if(c.charCodeAt() == 46){
if((beforeC.match(/\w/) && afterC.match(/\d/)) || (beforeC.match(/\d/) && afterC.match(/\w/))){
dot = false;
}
}
if (c.match(/\d/)) {
ary.push(c);
} else if ((mindex > -1 && mindex <= i && mmindex >= i && dot) || (aindex > -1 && aindex <= i)) {
if (c.match(/\w/)) {
ary.push(c);
} else {
if (c.charCodeAt() < 128 && c.charCodeAt() != 46) {
if (ary.length) {
ts.push(ary.join(""));
ary = [];
}
} else
ary.push(c);
}
} else if (ary.length) {
ts.push(ary.join(""));
ary = [];
}
}
if (ary.length) ts.push(ary.join(""));
for (var i = 0, j = 0, fl = fmt.length; j < fl; ++j) {
var cc = fmt.charAt(j);
if ((cc >= 'a' && cc <= 'z') || (cc >= 'A' && cc <= 'Z')) {
var len = 1;
for (var k = j; ++k < fl; ++len)
if (fmt.charAt(k) != cc)
break;
var nosep; //no separator
if (k < fl) {
var c2 = fmt.charAt(k);
nosep = c2 == 'y' || c2 == 'M' || c2 == 'd' || c2 == 'E';
}
var token = ts[i++] ;
switch (cc) {
case 'y':
if (nosep) {
if (len <= 3) len = 2;
if (token && token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
}
y = $int(token);
if (isNaN(y)) return null; //failed
if (y < 100) y += y > 29 ? 1900 : 2000;
break;
case 'M':
var mon = txt.substring(j).toLowerCase().trim(),
mToken = token ? token.toLowerCase() : '';
for (var index = zk.SMON.length; --index >= 0;) {
var smon = zk.SMON[index].toLowerCase();
if (mon.startsWith(smon) || (mToken && mToken.startsWith(smon))) {
token = zk.SMON[index];
m = index;
break;
}
}
if (len == 3 && token) {
break; // nothing to do.
}else if (len <= 2) {
if (nosep && token && token.length > 2) {//Bug 2560497 : if no seperator, token must be assigned.
ts[--i] = token.substring(2);
token = token.substring(0, 2);
}
m = $int(token) - 1;
if (isNaN(m)) return null; //failed
} else {
for (var l = 0;; ++l) {
if (l == 12) return null; //failed
if (len == 3) {
if (zk.SMON[l] == token) {
m = l;
break;
}
} else {
if (token && zk.FMON[l].startsWith(token)) {
m = l;
break;
}
}
}
}
break;
case 'd':
if (nosep) {
if (len < 2) len = 2;
if (token && token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
}
d = $int(token);
if (isNaN(d)) return null; //failed
break;
case 'H':
if (hasHour1)
break;
if (nosep) {
if (len < 2) len = 2;
if (token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
}
hr = $int(token);
if (isNaN(hr)) return null; //failed
break;
case 'h':
if (!hasHour1)
break;
if (nosep) {
if (len < 2) len = 2;
if (token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
}
hr = $int(token);
if (hr == 12)
hr = 0;
if (isNaN(hr)) return null; //failed
break;
case 'K':
if (!hasHour1)
break;
if (nosep) {
if (len < 2) len = 2;
if (token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
}
hr = $int(token);
if (isNaN(hr)) return null; //failed
hr %= 12;
break;
case 'k':
if (hasHour1)
break;
if (nosep) {
if (len < 2) len = 2;
if (token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
}
hr = $int(token);
if (hr == 24)
hr = 0;
if (isNaN(hr)) return null; //failed
break;
case 'm':
if (nosep) {
if (len < 2) len = 2;
if (token.length > len) {
ts[--i] = token.substring(len);
token = token.substring(0, len);
}
}
min = $int(token);
if (isNaN(min)) return null; //failed
break;
case 's':
if (nosep) {
if (len < 2) len = 2;
if (token && token.length > len) {
ts[i] = token.substring(len);
token = token.substring(0, len);
}
}
sec = $int(token);
if (isNaN(sec)) return null; //failed
break;
case 'a':
if (!hasHour1)
break;
if (token)
isAM = token.startsWith(zk.APM[0]);
break;
//default: ignored
}
j = k - 1;
}
}
if (hasHour1 && isAM === false) {
hr += 12;
}
var dt = new Date(y, m, d, hr, min, sec);
if (strict) {
if (dt.getFullYear() != y || dt.getMonth() != m || dt.getDate() != d ||
dt.getHours() != hr || dt.getMinutes() != min)
return null; //failed
txt = txt.trim();
txt = zk._ckDate(zk.FDOW, txt);
txt = zk._ckDate(zk.SDOW, txt);
txt = zk._ckDate(zk.S2DOW, txt);
txt = zk._ckDate(zk.FMON, txt);
txt = zk._ckDate(zk.SMON, txt);
txt = zk._ckDate(zk.S2MON, txt);
txt = zk._ckDate(zk.APM, txt);
for (var j = txt.length; --j >= 0;) {
var cc = txt.charAt(j);
if ((cc > '9' || cc < '0') && fmt.indexOf(cc) < 0)
return null; //failed
}
}
return dt;
};
// END ZK Datebox fix
/////////////////////////////////////////////
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.