問題描述
GXT NumberField 不可編輯 (GXT NumberField not editable)
I'm using Gxt‑2.2.0 and GWT 2.0. And GXT Numberfileds is not editable.
What can I do for editable NumberFields?
Following code is hopeless;
NumberField field = new NumberField();
field.setEditable(true);
‑‑‑‑‑
參考解法
方法 1:
I take the answer from GXT Development Team. The simple solution is upgrading Gxt‑2.2.0 to GXT‑2.2.1. This upgrade solved the problem.
Source
方法 2:
It's editable, your code must simply work, the problem seems with the number field implementation.
It accepts only characters from 0‑9, seems for some locale setting in your browser, it's sending characters other than 0‑9. you can try other browser (in my case it was working in IE and not in Firefox)
Now to solve your problem you have to set the characters it accepts by calling:
// They are by default 0‑9 change them to your locale numbers
field.setBaseChars("0123456789");
if you don't know what are the locale number characters, you can debug in this method in the NumberField class (inspect key variable):
protected void onKeyPress(FieldEvent fe) {
super.onKeyPress(fe);
char key = (char) fe.getKeyCode();
if (fe.isSpecialKey(lastKeyCode) || lastKeyCode == KeyCodes.KEY_BACKSPACE
|| lastKeyCode == KeyCodes.KEY_DELETE || fe.isControlKey()) {
return;
}
if (!allowed.contains(key)) {
fe.stopEvent();
}
}