0

Default time in the Datebox's pop up

asked 2012-04-23 10:22:19 +0800

duggudear gravatar image duggudear
15

Hi All,

I am using Datebox in my zkoss application for getting a pair of start and end dates 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:01' 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.

Thanks In Advance,
duggudear

delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2012-04-23 12:15:19 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

updated 2012-04-23 12:17:59 +0800

could you post a sample code?
in zk fiddle better...

link publish delete flag offensive edit

answered 2012-04-23 14:29:09 +0800

duggudear gravatar image duggudear
15

Thanks for the reply mhj.

Please see the sample code here. Currently, the startDate and endDate dateboxes display the current time as the initial time in the datebox's popup. I want to modify this initial time to "00:01" for startDate and "23:59" for endDate.

link publish delete flag offensive edit

answered 2012-04-23 16:12:53 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

duggudear:
look the code below:

ZKFiddle-Link

TestComposer.java
package j263jmhm$v1;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import java.util.Date;
import java.util.Calendar;

public class TestComposer extends GenericForwardComposer{
private Datebox startDate,endDate;

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
startDate.setValue(addHour(new Date(), 00,01));
endDate.setValue(addHour(new Date(), 23,59));
}

public void onClick$btn(Event e) throws InterruptedException{
Messagebox.show("Hi btn");
}

private Date addHour(Date date, int h, int m) {
if (date == null) {
throw new IllegalArgumentException("The date must not be null");
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.HOUR, h);
c.set(Calendar.MINUTE, m);
return c.getTime();
}
}


index.zul
<zk>
<window border="normal" title="Get Dates" apply="j263jmhm$v1.TestComposer">

<div>Please input the dates below:</div>

<separator height="10px" />

<hbox>
<label value="Fr:" />
<datebox id="startDate" format="yyyy-MM-dd HH:mm" mold="rounded" width="150px" />
</hbox>

<separator height="10px" />

<hbox>
<label value="To:" />
<datebox id="endDate" format="yyyy-MM-dd HH:mm" mold="rounded" width="150px" />
</hbox>
</window>
</zk>

link publish delete flag offensive edit

answered 2012-04-24 07:01:24 +0800

duggudear gravatar image duggudear
15

Thanks for the code mhj. But the TestComposer sets the desired time directly to the dateboxes. My requirement is to set "00:01" and "23:59" as the initial time in the datebox's popup, i.e, when user clicks on the datebox for the first time and when the datebox popup comes up, the time displayed in the respective timeboxes should be "00:01" and "23:59" respectively instead of the current time. User may then change the time from the given initial time, which would then be set to the dateboxes. For example, when I first click on the 'startDate' datebox, the popup which opens up should have the day as the current day and time as "00:01". Then, suppose I change the time to "11:00" from "00:01" and the datebox value should be "2012-04-24 11:00". Hope the requirement is clear now.

link publish delete flag offensive edit

answered 2012-04-24 08:37:46 +0800

Matze2 gravatar image Matze2
773 7

updated 2012-04-24 08:40:11 +0800

Sounds like a useful "Feature Request" to me, e.g a new attribute "defaultTime" in datebox could easily solve that.

link publish delete flag offensive edit

answered 2012-04-25 06:20:35 +0800

duggudear gravatar image duggudear
15

Would be a really useful feature indeed. I am not sure how to raise a New Feature request in zkoss. Will go through the Help docs and do that if possible.

Also, I have now implemented a work around for the requirement by using zkoss bandbox, the click of which will open a popup containing a calendar as well as a timebox. It looks exactly like the datebox. Since I have the reference to the timebox instance in this case, I am setting its value to the desired default time if the bandbox's text is empty.

link publish delete flag offensive edit

answered 2012-04-25 08:20:49 +0800

Matze2 gravatar image Matze2
773 7

Main menu "Community/Request Features" guides you to ZK JIRA tracker.
You may need to login again with the same credentials as in the forum.

link publish delete flag offensive edit

answered 2014-08-12 10:41:08 +0800

ivantufa gravatar image ivantufa
1

Hi, I need the same thing. Have you created new java script to work same as datebox (onchange,...)? Do you have some example of your solution/workaround?

Thank you in advance.

link publish delete flag offensive edit

answered 2017-10-12 14:31:17 +0800

abulgaris gravatar image abulgaris
0

Hi There,

I am facing the same issue. The display time in datebox is always set to current time. Has a solution been found for this problem ?

Thank you in advance!

link publish delete flag offensive edit

answered 2017-10-13 14:54:07 +0800

hawk gravatar image hawk
3225 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2017-10-13 14:59:52 +0800

I have created a feature request for this: http://tracker.zkoss.org/browse/ZK-3769 Please read this to avoid my misunderstanding to your requirement. If you have any comments, just feel free to add it in the tracker.

In that tracker, there is a workaround. Please apply it. It allows you to set default time with a data attribute like:

<datebox format="yyyy-MM-dd HH:mm" width="200px" ca:data-default-time="00:01:00"/>
link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2012-04-23 10:22:19 +0800

Seen: 444 times

Last updated: Oct 13 '17

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More