2016-08-17 26 views
0

所以我需要製作自定義數字單元格,其中逗號前爲20位數字,逗號後爲16位十進制數字。 試圖覆蓋onKeyDown(),但它不會動態檢查鍵入的值,僅在模糊之前纔有效。任何幫助?Sencha GXT NumberInputCell length

回答

0

嘗試這樣的事情。

import com.google.gwt.cell.client.ValueUpdater; 
import com.google.gwt.core.client.EntryPoint; 
import com.google.gwt.dom.client.Element; 
import com.google.gwt.dom.client.NativeEvent; 
import com.google.gwt.user.client.ui.RootPanel; 
import com.sencha.gxt.cell.core.client.form.NumberInputCell; 
import com.sencha.gxt.widget.core.client.form.NumberField; 
import com.sencha.gxt.widget.core.client.form.NumberPropertyEditor.IntegerPropertyEditor; 

public class NumberFieldTest implements EntryPoint { 

    @Override 
    public void onModuleLoad() { 

    IntegerPropertyEditor integerEditor = new IntegerPropertyEditor(); 

    NumberInputCell<Integer> numberFieldCell = new NumberInputCell<Integer>(integerEditor) { 
     @Override 
     protected void onKeyPress(com.google.gwt.cell.client.Cell.Context context, Element parent, Integer value, 
      NativeEvent event, ValueUpdater<Integer> valueUpdate) {   
     super.onKeyPress(context, parent, value, event, valueUpdate); 

     String textValue = getInputElement(parent).getValue(); 
     if (textValue != null && textValue.length() > 3) { 
      event.stopPropagation(); 
      event.preventDefault(); 
     } 
     } 
    }; 

    NumberField<Integer> numberField = new NumberField<Integer>(numberFieldCell, integerEditor); 

    RootPanel.get().add(numberField); 
    } 

} 
+0

是的,那還挺好的解決方案。爲外地。不是細胞。因爲單元格可以在某種網格中使用,並且驗證應該完全附加到單元格上。 –

+0

啊,我很快就讀了。我已經改變了這個例子來展示你如何在單元格中完成它。 – Branflake2267