-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a problem with the Calendar component and cannot figure out how to fix it.
Let's look at a simple example:
Window win = new Window(); Vbox vbox = new Vbox(); Separator separator = new Separator("horizontal"); separator.setHeight("1000px"); separator.setParent(vbox); Calendar cal = new Calendar(); cal.setParent(vbox); vbox.setParent(win); win.setPage(page);
For simplicity I use a 1000px Separator in my example, but it doesn't matter what components there are in the page, what matters is that you have to scroll down to see the Calendar. Now any click on the Calendar, picking a different Date etc, causes the entire page to to scroll back to the top. As a result, when I try to use the Calendar component further down in a longer scrolling form and you wish to enter a date that's a couple of years and months away the process of click-scroll back down-click-scroll down... takes ages and renders the component nothing short of useless.
The problem is the same in Firefox 5, IE9 and Chromium.
Should this have been discussed before I apologise, but I couldn't find anything relating to the issue.
Hi Andiklein,
in this case, add win.setVflex("1"); or win.setHeight("300px");
assign window a height to fix it.
Hi benbai.
Thank you, I've just tried your suggestions (and I was sure I had already tried that earlier), sadly however it doesn't solve the problem.
With a vflex of 1 the page still jumps to the top every time I click the calendar, if I set a fixed height for the window all overflowing content incl. the calendar itself is of course hidden and unusable.
Same goes for a combination of the two or setting a fixed window height that is greater than the required space, e.g. win.setHeight("2000px").
All that achieves is unnessecary whitespace and a longer scrollbar, but the click-the-calendar->jump-to-top issue remains.
Unfortunately the calendar component does not accept manually giving it the focus either, so a dirty workaround using events and cal.focus() doesn't work.
If there is a focussable component, say a textbox, further down the page, you can use an onChange Event on the calendar and have the listener focus on that component instead whenever cal changes (Sadly this event is not triggered by all possible actions in the calendar either).
Window win = new Window(); Vbox vbox = new Vbox(); Separator separator = new Separator("horizontal"); separator.setHeight("1000px"); separator.setParent(vbox); final Calendar cal = new Calendar(); final Textbox someTb = new Textbox(); EventListener focusLst = new EventListener() { @Override public void onEvent(Event event) throws Exception { someTb.focus(); } }; cal.addEventListener(Events.ON_CHANGE, focusLst); cal.setParent(vbox); someTb.setParent(vbox); vbox.setParent(win); win.setPage(page);
But in any case this would of course be a very ugly hack at best.
it can be solved by setting scroll by win.setContentStyle();
please refer to test window scroll with bottom calendar
click 'Run' button at top right to see the result.
Thanks again benbai.
The example you sent works fine in Fiddle but still fails when I put everything inside a simple Richlet.
I'm not using ZUL but prefer coding directly in Java based on ZK Richlets.
Here's my code, you'd expect it works exactly like your script:
import org.zkoss.zk.ui.GenericRichlet; import org.zkoss.zk.ui.Page; import org.zkoss.zul.Calendar; import org.zkoss.zul.Separator; import org.zkoss.zul.Vbox; import org.zkoss.zul.Window; public class TestRichlet extends GenericRichlet { public TestRichlet() { } @Override public void service(Page page) { page.setTitle("TEST RICHLET"); Window win = new Window(); win.setVflex("1"); win.setContentStyle("overflow: auto"); Vbox vbox = new Vbox(); Separator separator = new Separator("horizontal"); separator.setHeight("1000px"); separator.setParent(vbox); Calendar cal = new Calendar(); cal.setParent(vbox); vbox.setParent(win); win.setPage(page); } }
Hi Andiklein,
I tried your code and it works fine for me,
the record swf file:
calendar with window in richlet
Asked: 2011-07-12 09:49:08 +0800
Seen: 3,951 times
Last updated: Jul 30 '11