Kamal 149 posts since
Oct 17, 2007
1.
Re: delete or backspace on a DateField Jul 5, 2008 7:02 AM
Here is an idea how to go about this. Note that in the given example below, as soon as the date will become invalid, the DateField value is unset. You can extend on this idea to only do it when you want. The best place to do this will be at the UI end as you may have more control. However you can do this by sub classing the control (the advantage is that, this will work for4 all UIs).
This solution takes advantage of the fact that the UI calls DateField.get-parsed-value to convert a String to a Date. If it cannot it throws a ValidationException.
I would suggest reading the source code of DateField and DateFieldUI(s) for constructing your own solution.
{curl 6.0 applet}
{define-class public CustomDateField {inherits DateField}
{constructor public {default
ui-object:#DateFieldUI = null,
min-value:#DateTime = null,
max-value:#DateTime = null,
value:#DateTime = null,
prompt:#String = null,
locale:#Locale = null,
calendar-control:CalendarControl =
{CalendarControl takes-focus? = false},
...
}
{construct-super
ui-object = ui-object,
min-value = min-value,
max-value = max-value,
value = value,
prompt = prompt,
locale = locale,
calendar-control = calendar-control,
...
}
}
{method public {get-parsed-value
val:String,
require-four-digit-year?:bool = false
}:(date:DateTime,
day-start-pos:int, day-end-pos:int,
month-start-pos:int, month-end-pos:int,
year-start-pos:int, year-end-pos:int)
{try
{return
{super.get-parsed-value
val,
require-four-digit-year? = require-four-digit-year?
}
}
catch e:ValidationException do
{after 0s do
{self.unset-value}
}
{throw e}
}
}
}
Original DateField: {DateField}
Custon DateField: {CustomDateField}
Message was edited by: Kamal