Open gurcanaslan opened 11 years ago
We modified NumericFieldWidget class. Problem was backspace key not working. Only firefox browser. Maybe this is helpful for you...
package org.vaadin.addons.maskedtextfield.client;
import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.dom.client.KeyPressEvent; import com.google.gwt.event.dom.client.KeyPressHandler; import com.vaadin.client.ui.VTextField;
public class NumericFieldWidget extends VTextField { public NumericFieldWidget() { super(); addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent e) {
/**** UNIVERSAL GÜNCELLEME BEGIN **********/
// Window.alert("getNativeEvent KeyCode:" + String.valueOf(event.getNativeEvent().getKeyCode())); // Window.alert("Gelen: Char Code: " + String.valueOf(event.getCharCode()) + " UnicodeCharCode: " + String.valueOf(event.getUnicodeCharCode()) + " Type: " + event.getType().toString() + " Evnet String: " + event.toString() + " Event Debug String: " + event.toDebugString());
//Chrome backspace'da keypress'e girmiyor. int keyCode = e.getUnicodeCharCode(); if (keyCode == 0) { // Probably Firefox keyCode = e.getNativeEvent().getKeyCode(); } /**** UNIVERSAL GÜNCELLEME END **********/ if (e.getCharCode() == KeyCodes.KEY_BACKSPACE || e.getCharCode() == KeyCodes.KEY_DELETE || e.getCharCode() == KeyCodes.KEY_END || e.getCharCode() == KeyCodes.KEY_ENTER || e.getCharCode() == KeyCodes.KEY_ESCAPE || e.getCharCode() == KeyCodes.KEY_HOME || e.getCharCode() == KeyCodes.KEY_LEFT || e.getCharCode() == KeyCodes.KEY_PAGEDOWN || e.getCharCode() == KeyCodes.KEY_PAGEUP || e.getCharCode() == KeyCodes.KEY_RIGHT || e.getCharCode() == KeyCodes.KEY_TAB || e.isAnyModifierKeyDown()) return; if (!Character.isDigit(e.getCharCode())) e.preventDefault(); } }); addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { try { if (event.getNativeKeyCode() == KeyCodes.KEY_UP) { int value = Integer.parseInt(getValue()); value++; setValue(String.valueOf(value)); event.preventDefault(); } else if (event.getNativeKeyCode() == KeyCodes.KEY_DOWN) { int value = Integer.parseInt(getValue()); value--; setValue(String.valueOf(value)); event.preventDefault(); } } catch (Exception e) { setValue("0"); } } }); } @SuppressWarnings("unused") private String getValueToOperate(String value) { return value.length() > 1 ? value.substring(value.length() - 2) : value .substring(value.length() - 1); } @SuppressWarnings("unused") private String getLiteralValue(String value) { return value.length() > 1 ? value.substring(0, value.length() - 2) : value.substring(0, value.length() - 1); }
}
We modified NumericFieldWidget class. Problem was backspace key not working. Only firefox browser. Maybe this is helpful for you...
package org.vaadin.addons.maskedtextfield.client;
import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.dom.client.KeyPressEvent; import com.google.gwt.event.dom.client.KeyPressHandler; import com.vaadin.client.ui.VTextField;
public class NumericFieldWidget extends VTextField { public NumericFieldWidget() { super(); addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent e) {
// Window.alert("getNativeEvent KeyCode:" + String.valueOf(event.getNativeEvent().getKeyCode())); // Window.alert("Gelen: Char Code: " + String.valueOf(event.getCharCode()) + " UnicodeCharCode: " + String.valueOf(event.getUnicodeCharCode()) + " Type: " + event.getType().toString() + " Evnet String: " + event.toString() + " Event Debug String: " + event.toDebugString());
}