I have a DateTimeField
that I am trying to allow for 2 types of formats based on the user's preferences: MM/dd/yy
or dd/MM/yy
. When a user clicks DatePicker
and selects a date, I am able to display the date in a DateTextField
with the correct formatting. However, when I try to submit the form, I get "'date' is not a valid Date"
alert, which is the default alert for the DateTimeField
. Is there a way I can set, not just the pattern of the date, but the validation pattern too? I've tried implementing my own IValidator
and IConverter
as other posts have mentioned, but I am having no luck.
Here is the code for how I am altering the way the picked date is displayed in the DateTextField
:
DateTimeField fromDate = new DateTimeField("fromDate") {
private static final long serialVersionUID = 1L;
@Override
protected DatePicker newDatePicker() {
DatePicker datePicker = new DatePicker(){
private static final long serialVersionUID = 1L;
@Override
protected String getDatePattern() {
return ((String) getSession()
.getAttribute("dateFormat")).replace("yyyy", "yy");
}
};
return datePicker;
}