# Default time in the Datebox's pop up

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.

duggudear

delete retag edit

## 10 Replies

mhj
806 1 7

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

duggudear
15

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.

mhj
806 1 7

duggudear:
look the code below:

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>

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.

Matze2
773 7

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

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.

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.

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?

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 ?

hawk
2255 1 5
http://hawkphoenix.blogsp...

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"/>

[hide preview]