-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
could you post a sample code?
in zk fiddle better...
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.
duggudear:
look the code below:
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();
}
}
<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>
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.
Sounds like a useful "Feature Request" to me, e.g a new attribute "defaultTime" in datebox could easily solve that.
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.
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"/>
Asked: 2012-04-23 10:22:19 +0800
Seen: 444 times
Last updated: Oct 13 '17