0

Calendar: Every click/selection scrolls to top of the page

asked 2011-07-12 09:49:08 +0800

andiklein gravatar image andiklein
39 2 2

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.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2011-07-22 03:12:40 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi Andiklein,

in this case, add win.setVflex("1"); or win.setHeight("300px");
assign window a height to fix it.

link publish delete flag offensive edit

answered 2011-07-22 19:32:16 +0800

andiklein gravatar image andiklein
39 2 2

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.

link publish delete flag offensive edit

answered 2011-07-22 20:43:32 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

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.

link publish delete flag offensive edit

answered 2011-07-24 03:22:12 +0800

andiklein gravatar image andiklein
39 2 2

updated 2011-07-24 03:24:07 +0800

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);
	}

}

link publish delete flag offensive edit

answered 2011-07-24 05:58:33 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi Andiklein,

I tried your code and it works fine for me,
the record swf file:
calendar with window in richlet

link publish delete flag offensive edit

answered 2011-07-24 08:24:02 +0800

andiklein gravatar image andiklein
39 2 2

Wow, thanks for that benbai.

link publish delete flag offensive edit

answered 2011-07-30 21:21:38 +0800

andiklein gravatar image andiklein
39 2 2

Eureka!

I switched to the Breeze theme and lo and behold - the problem is history.

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

RSS

Stats

Asked: 2011-07-12 09:49:08 +0800

Seen: 3,951 times

Last updated: Jul 30 '11

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