-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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.
Asked: 2022-07-04 17:54:34 +0800
Seen: 8 times
Last updated: Jul 05 '22