Monday, September 6, 2010

Re: Getting intelligent behavior out of DateBox

In a standard DateBox, the DatePicker is automatically visible when
the DateBox gets focus.

To change the parsing rules for dates typed by the user, you'll want
to write a custom date parser. The basic approach is to subclass
DateBox and do this:

setFormat(new CustomDateFormat(getFormat());
...
private static class CustomDateFormat extends
DateBox.DefaultFormat
{
public CustomDateFormat(DateTimeFormat dateTimeFormat)
{
super(dateTimeFormat);
}

@Override
public Date parse(CustomDateBox dateBox, String dateText,
boolean reportError)
{
Date date = null;
// First, see if the GWT date parser can handle it
try
{
if (dateText.length() > 0)
{
date = getDateTimeFormat().parseStrict(dateText);
}
}
catch (Exception e)
{
// http://code.google.com/p/google-web-toolkit/issues/detail?id=4633
}
// If GWT couldn't parse it, try my custom date parser
if (date == null)
{
// custom code...parse the date however you like:
date = customParseDate(dateText);
}
return date;
}
}


On Sep 5, 7:59 pm, GregD <gre...@gmail.com> wrote:
> I'm writing an app for which DateBox could be quite useful.
> Unfortunately, its default behavior is so lacking that I can't use it,
> unless I can fix it.
>
> Issue 1: If I type in a month and day, instead of adding the current
> year, it reports an error.
> Issue 2: If I type in a date like :11/7/7, DateBox translates the date
> as November 7, 1907.
>
> Can I fix those behaviors?  Lacking that, anyone have a date picker
> icon I can use on a little button to bring up a DatePicker when my
> users want to deal with one?
>
> TIA,
>
> Greg

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment