MURAT8
(MURAT YILMAZ)
November 19, 2013, 2:39pm
1
Hi
I am trying to enter date to datefield without using dots (‘.’).Normally ı can successfully enter a date to a datefield using keyboard with dots without any problem .However I am wondering it is possible to enter a datefield without using dots as below
11192013 → 11/19/2013
Is there a simple way to do this ?
Regards
Kurki
(Teppo Kurki)
November 26, 2013, 11:14am
2
As far as I know there’s no automatic way to do this. However, you can override the handleUnparsableDateString of DateField and parse the dotless input into a proper Date object yourself.
Johannes13
(Johannes Dahlström)
November 26, 2013, 11:23am
3
Surely
DateField.setDateFormat()
should work?
Kurki
(Teppo Kurki)
November 26, 2013, 11:38am
4
Surely. I assumed he wants to keep accepting dates with separator characters also, which I think is not possible with a single date format.
MURAT8
(MURAT YILMAZ)
November 26, 2013, 12:10pm
5
Thanks a lot for your responses.
I wanted the clarify the situation here.The thing that i am trying to do is not formatiing the dateField value.
I want to enter to the datefield without any delimiters ,After i entered the value i expect the field value automatically be formatted.
Before enter
11192013
After enter
11/19/2013
Is this possible ?
Kurki
(Teppo Kurki)
November 26, 2013, 12:19pm
6
Try this:
DateField df = new DateField() {
protected Date handleUnparsableDateString(String dateString)
throws ConversionException {
DateFormat df = new SimpleDateFormat("MMddyyyy");
try {
return df.parse(dateString);
} catch (ParseException e) {
throw new ConversionException("Cannot parse: " + dateString);
}
};
};
df.setDateFormat("MM/dd/yyyy");
df.setImmediate(true);
MURAT8
(MURAT YILMAZ)
November 27, 2013, 1:43pm
7
Thanks a lot Teppo ,Johannes.
My problem is resolved by overriding handleUnparsableDateString metod.
Regards.