1

How to avoid entering particular value in editTextCell- column- Celltable?

Is there any event in editTextCell?

Validation while entering values in cells of celltable
In case of
String :Dont enter spaces in cell
Integer : Dont use characters

  • avoiding spaces in cell i.e if cell is type of string then user can't use spaces for although user presses "space bar" button multiple times then that spaces should not be enter in cell a How to achieve this ?

Any help or guidance in this matter would be appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
StackOverFlow
  • 4,486
  • 12
  • 52
  • 87

2 Answers2

3

If you want a specific behavior in a Cell, then you have a to make a Cell with that behavior built in.

You could start with an EditTextCell if that's what you want, and then extend it and override its onBrowserEvent to cancel key events for spaces when in edit mode, or something like that.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks for reply. How to cancel key events for spaces when in edit mode? – StackOverFlow Mar 28 '12 at 03:59
  • You mean [cancelling events](http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/dom/client/NativeEvent.html#preventDefault%28%29) whose [type](http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/dom/client/NativeEvent.html#getType%28%29) is `keypress`, when [in edit mode](http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/cell/client/Cell.html#isEditing%28com.google.gwt.cell.client.Cell.Context,%20com.google.gwt.dom.client.Element,%20C%29)? – Thomas Broyer Mar 28 '12 at 09:13
  • Can you provide sample code for the same ? onBrowserEvent { // How to avoid entering particular value like space (spacebar) ?} – StackOverFlow May 07 '12 at 08:45
0

Here is the answer with sample code :)
KeyCode of SpaceBar 32

 @Override
            public void onBrowserEvent(Context context, Element parent,
                    String value, NativeEvent event,
                    ValueUpdater<String> valueUpdater) {
                super.onBrowserEvent(context, parent, value, event, valueUpdater);
                boolean isEditing = isEditing(context, parent, value);

                if(isEditing){
                    if(event!=null){
                        info(" event.getKeyCode() = "+event.getKeyCode()+" :: value ="+value);
                        if(event.getKeyCode()==32)){
                            event.preventDefault();
                            return;
                        }
                    }
                }
            }
StackOverFlow
  • 4,486
  • 12
  • 52
  • 87