Bernd
Bernd

Reputation: 657

GWT - Not able to input text into TextArea

I have a strange problem to solve. I have a GWT Textarea where it is not possible to input text to it, however, I am able to setText automatically.

I already tried to

textBox.setEnabled(true);
textBox.setFocus(true);
textBox.setReadOnly(false);

but it has not changed anything. When going through the css file, everything seems to me ok.

Here is the "whole" source code:

private Input(AbsolutePanel canvas) {

    textBox = new MouseEventTextBox();
    textBox.setStylePrimaryName(PRIMARY_STYLE);
    textBox.addKeyUpHandler(this);
    textBox.addKeyDownHandler(this);
    textBox.addFocusHandler(this);
    textBox.addBlurHandler(this);
    textBox.setEnabled(true);
    textBox.setFocus(true);
    textBox.setReadOnly(false);
    textBox.setText("Just an apple"); // Works, text is set but not editable
    canvas.add(textBox, -1000, -1000);
}

private class MouseEventTextBox extends TextArea{
    public MouseEventTextBox() {
        super();
        sinkEvents(Event.MOUSEEVENTS);
    }

    public void onBrowserEvent(Event event) {
        // Call the superclass' implementation first.
        super.onBrowserEvent(event);

        if ((DOM.eventGetButton(event) == Event.BUTTON_LEFT) && (DOM.eventGetType(event) == Event.ONMOUSEUP)) {
            this.setReadOnly(false);
            DOM.eventCancelBubble(event, true);
        }
    }
}

CSS

border-width: 0px;
background-color: #fffde5;
padding-top: 2px;
padding-left: 3px;
padding-right: 3px;
padding-bottom: 1px;
z-index: 50;
overflow: hidden;

Maybe, someone could give me a hint or know what is going wrong here?

Thank you very much!

Upvotes: 1

Views: 348

Answers (1)

Adam
Adam

Reputation: 5599

The suspicious part of your code is:

textBox.addKeyUpHandler(this);
textBox.addKeyDownHandler(this);
textBox.addFocusHandler(this);
textBox.addBlurHandler(this);

That means, that this implements KeyUpHandler, KeyDownHandler, FocusHandler and BlurHandler. Unfortunately, you did not show us methods that handles those events.

I bet, that there is something wrong in your onKeyDown method. I was able to achieve the same behavior when I blocked the KeyDownEvent event (stopPropagation, preventDefault).

Check your browser console for errors. If none, comment out textBox.addKeyDownHandler(this); line.

Upvotes: 4

Related Questions