0

Datebox with optional format

asked 2022-07-04 17:54:34 +0800

AndreiArdei gravatar image AndreiArdei
101 2

Hi!

Is it possible to set an optional format to the datebox component? For example dd-MM[-YYYY] would accept both 22/07 and 22/07/2022.

My end goal is to allow users to write only day and month and assume that year is the current year.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-07-05 22:17:21 +0800

MDuchemin gravatar image MDuchemin
2146 1 5
ZK Team

Hello there,

There isn't exactly that behavior out of the box.

First ZK datebox comes with 2 properties which you may want to check out.

Lenient: this attribute let you choose if you want the datebox to accept strings that are not an exact match to your provided format string. If lenient is true (by default), the user already can put a partial date and have the listbox fill the rest for them.

strictDate: this attribute let you choose if the user can enter an non-valid date (with a valid format) such as June 0 2022, or June 31 2022. If strictDate is false, the datebox will adjust the date to be valid. June 0 will transform into may 31, june 31 will transform into July 1, etc.

Now, if you wanted to change how the datebox at client-side handles the input string and transform it into a date, you could intercept that string with an override:

https://zkfiddle.org/sample/311nbvd/1-Another-new-ZK-fiddle

This sample does nothing, but it shows how you would override the coerceFromString method to change the input before it is parsed by the datebox.

link publish delete flag offensive 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

RSS

Stats

Asked: 2022-07-04 17:54:34 +0800

Seen: 7 times

Last updated: Jul 05

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