View Full Version : How can i resolve Time Field selection problem ?

4 Nov 2011, 12:42 AM
Hi All,

In my application i am using 8 TimeField components in formpanel.

User can select the value from TimeField component as well as he can Type in to TimeFiled component.
I am using AM/PM date format in TimeField component.

Problem is : if user typed value is not available in TimeField store then null will return in binding.

How to resolve this problem .

Can you please give me solution other than timeField.setIncrement(1) ?

because timeField.setIncrement(1) throwing script error in IE8 with Windows ,FF6,FF7.

Each TimeField contain long list (1440 entries). and total 8 TimeFields having 11520 values.
This is impact in when formpanel loading in IE8 and FF 6/7 throwing script error.

If i set timeField.setIncrement(30); (like 10:00 AM 10:30 AM )then this problem will resolve.But another problem is raising.

If user type valid time like 10:05 AM .this is not available in TimeField store so null will assign in binding.

Sample code here :

TimeField timeField = new TimeField();
timeField.setFormat(DateTimeFormat.getFormat("h:mm a"));
timeField.setValidator(new Validator() {

public String validate(Field<?> field, String value) {
try {
if (value != null && !value.isEmpty()) {
if (value.contains(":")) {
String time[] = value.split(":");
if (Integer.parseInt(time[0].toString()) > 12) {
return LocaleManager.getInstance().getMessage(

DateTimeFormat dateFormat = DateTimeFormat
.getFormat("h:mm a");
Date tempDate = dateFormat.parseStrict(value);
if ((tempDate.getHours() - 12) > 12
|| tempDate.getMinutes() > 59)
return LocaleManager.getInstance().getMessage(

return null;
} catch (IllegalArgumentException exp) {

//Window.alert("setTimeFieldProperties Excpetion :"+exp);
return LocaleManager.getInstance().getMessage(

TimeFieldBinding startBinding = new TimeFieldBinding(timeField, "startTime") {
protected Object onConvertFieldValue(Object value) {
if (value == null) {
return null;
return ((Time) value).getText();

protected Object onConvertModelValue(Object value) {

if (value == null) {
return null;
DateTimeFormat dateFormat = DateTimeFormat.getFormat("h:mm a");
Date tempDate = dateFormat.parse(value.toString());
return timeField.findModel(tempDate);


i searched so many entries in this forum but not found the proper solution.

This is pretty urgent.
Can you please help me out in this issue.

4 Nov 2011, 2:41 AM
You could change the getValue method of TimeField, that if the value is not in the store automatically creates it and adds it to the store.

4 Nov 2011, 3:27 AM
Hi sven,

Thanks for your response.

Do you have sample code or example to resolve this problem ?

4 Nov 2011, 3:30 AM
Sorry, I do not have any example code for this.

26 Jan 2012, 9:19 AM

I had similar problem and the easiest workaround that I found is to use timeField.getRawValue() method, which really contains what user entered in field, no matter if value is in a model or not. Of course, manual validation and parsing to get Date object is needed if getRawValue() is used.

I consider this being GXT bug, TimeField.getValue() and getDateValue() should return even dates not contained in the popup menu list if 'forceSelection' property is set to false. What do you think?


Dafe Simonek

26 Jan 2012, 10:31 AM
I consider this being GXT bug, TimeField.getValue() and getDateValue() should return even dates not contained in the popup menu list if 'forceSelection' property is set to false. What do you think?

This would be a braking change and cannot be implemented. I would not say it is a bug as it was never intended to work like this. You could easily subclass TimeField to add this feature