0

Set default date for zul datebox

asked 2019-07-18 20:27:19 +0800

obeliksz gravatar image obeliksz
33 1

I had to remove the links, the question with links is on stackoverflow with same title.

I inherited a legacy website written in old zul and have to add new datebox component for birthday datepicker.

Have added a constraint to accept dates before a given date but that triggers an error alertbox from start as the date presented/selected by default on the datepicker is today.

I wouldn't want to use a workaround but to all due respect it seems like this is something over the top feature I'm looking for in zk's reality:

The main showcase for zul does include a birthday datebox, but pretty lame as it doesn't contain any constrain on age. There is zk flicker to show how the before constrain works, but that just proves my point that it doesn't select the first proper date for default date at least, if there is no clean way of setting it. There is forum post that proposes a workaround to set the default year, so Zk is most probably incapable of doing this without a workaround. There is an open ZK Jira issue from 2017 that addresses somewhat this issue, with a proposed solution pretty much the same as the workaround mentioned in the above point - so the hope is kinda lost, have to go on the workaround route. I did try that workaround (after the forum post, as that has default year), but the workaround doesn't work for me. It does execute the

this.setValue(initialDate); And I see that the value is set into the datebox's pop/value and pop/end nodes but no difference is visible on the datepicker box, still today is preselected altough it is greyed out - so no effect. Still, when I try it in a fiddle with version 6.5.8.1, the oldest engine that exists, it does work, but not locally with version 5.0.11 (just older with 1.5.7

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-07-19 17:36:15 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

Hi obeliksz,

I bumped up your rep a bit, you should be able to post links now :)

ZK 5.0.11 is a bit on the older side currently, so it might not accept exactly the same overrides as later versions. If I understand the issue correctly, it boils down to either

1 - setting a value before Datebox is rendered to have a "initial date" opened in calendar.

I'd say that's the easy way out, since you can use either composing or databinding to set the value of the datebox during page rendering. Here's a small sample using databinding and zscripts, but the same logic should apply from composer with setValue(). You mentioned that this doesn't work for you locally with 5.0.11 though. Can you share the code that you are using for this? Sample code here in fiddle I can run it on local 5.0.11, and it set the date before popup is opened.

or

2 - setting an initial date (which doesn't affect the selected value) but would be the target for the opened calendar.

This is not a default ZK 5 behavior for datebox. If you want that effect, you would need to customize it using an override script. Simplest way in can think of in ZK 5 is to use the open event of the datebox popup here's an example of what it would look like (package in a script tag in a single page for the example, would use a global js file for real deployement) example here

Any of those match what you are trying to do?

link publish delete flag offensive edit

Comments

Thanks for your help. Yep, legacy software. 1. I should leave it up to the user to select the date to prevent unintended submit. 2. Spot on. Could you also comment on constraint alerts popping up many times after I close it, cant reproduce this on fiddler... Would you also post the answer to SO?

obeliksz ( 2019-07-19 19:41:45 +0800 )edit
0

answered 2019-07-20 00:34:46 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

Hi again. I've posted the same answer to SO for clarity.

On the alerts: closing an alert in ZK 5 by clicking the cross (X) button will put the focus back in the datebox. When focusing out of the datebox, the datebox revalidates and shows the alert again. Does that looks like the behavior that you are encountering?

link publish delete flag offensive edit

Comments

probably that is it.

obeliksz ( 2019-07-20 13:29:23 +0800 )edit

That was updated in later ZK versions.

MDuchemin ( 2019-07-25 10:30:51 +0800 )edit

If you have access to an event, you can use Clients.clearWrongValues to remove the error message, but that might be annoying if you don't already have listeners ready.

MDuchemin ( 2019-07-25 10:33:01 +0800 )edit

Otherwise, might be done with overrides on the datebox or its popup

MDuchemin ( 2019-07-25 10:34:20 +0800 )edit
Your answer
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: 2019-07-18 20:27:19 +0800

Seen: 13 times

Last updated: Jul 20 '19

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