PDA

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



Av-swdev-4
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.setTriggerAction(TriggerAction.ALL);
timeField.setForceSelection(false);
timeField.setTypeAhead(true);
timeField.setEditable(true);
timeField.setLazyRender(false);
timeField.setIncrement(30);
timeField.setFormat(DateTimeFormat.getFormat("h:mm a"));
timeField.setFireChangeEventOnSetValue(true);
timeField.setWidth(90);
timeField.setMaxHeight(80);
timeField.setAutoValidate(true);
timeField.setAllowBlank(false);
timeField.setValidator(new Validator() {




@Override
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(
"INVALID_DATE_FORMAT");
}
}
}


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




return null;
} catch (IllegalArgumentException exp) {


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


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


@Override
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.
Thanks

sven
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.

Av-swdev-4
4 Nov 2011, 3:27 AM
Hi sven,

Thanks for your response.

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

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

simda15
26 Jan 2012, 9:19 AM
Hello,

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?

Regards,

Dafe Simonek

sven
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