Reputation: 31245
I have a GXT 3 TextArea on which I catch copy-paste events. On this event, I would like to get the text that is inside the textarea.
Problem : the textarea still has the focus so the value is not updated. Hence, getValue()
returns an empty string...
I tried to call getValue()
getCurrentValue()
flush()
validate()
.
I also tried to extend TextArea
to have access to blur()
method and call it before getting the value : it makes no difference.
Any solution? (even solution with GWT components would be appreciated).
Upvotes: 1
Views: 760
Reputation: 1270
Before getting the value you can call
yourTextField.finishEditing();
After it method getValue()
should return the value of the field. If you would like to keep this field focused after getting the value you can always call
yourTexField.focus();
Upvotes: 0
Reputation: 18346
Without seeing the code you have, it is difficult to say for sure. But at a guess, you are listening to the event, and invoking getCurrentValue()
(the correct call in this case) right away.
This is wrong - it is possible for the event handler to call preventDefault()
, to cancel the default behavior of that event for most events that can take place. After the event handler returns, only then does the browser actually perform the action (paste or drawing the key that was pressed). The solution to this is to wait a moment before trying to read, to wait until after the action has been completed. The simplest way to achieve this is to schedule a deferred command after the event has occurred, and read the field's value then.
//in the event handler of your choice...
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
String pastedValue = field.getCurrentValue();
//do something with the value now
}
});
Upvotes: 2