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