how to disable backspace button in gwt?

485 views
Skip to first unread message

Mohammed Sameen

unread,
Jul 11, 2014, 5:18:29 AM7/11/14
to google-we...@googlegroups.com
Hi! 

My application does not need have any history 
support. 
The problem is that when I type something wrong in textbox,its shows warning in dialogbox and accidentally lose focus and 
then press Backspace key to delete a character from textbox,browser performs application to exit and the whole application is unloaded losing all the 
data. 

How can I disable this?Please give me suggestion.

Thanks! 

Jens

unread,
Jul 11, 2014, 6:44:57 AM7/11/14
to google-we...@googlegroups.com
Fix your UI and refocus the TextBox/TextArea after the dialog box is closed.

-- J.

Mohammed Sameen

unread,
Jul 11, 2014, 6:48:29 AM7/11/14
to google-we...@googlegroups.com
Jens,
Once the dialog box is appear that time unfortunately the user click the backspace which causes apps to exit..I need to handle this...any suggestion...

David

unread,
Jul 11, 2014, 7:47:58 AM7/11/14
to google-we...@googlegroups.com
Install a keyboard listener to catch the backspace and call preventDefault. 

I have done that in an application before, not very nice but it works.
I moved on to using the Activity/Places framework so that my GWT app supports the browser history correctly. Due to the rather limited documentation it looked quite daunting at first, but once put in place it is actually quite simple.





--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Mohammed Sameen

unread,
Jul 11, 2014, 7:55:54 AM7/11/14
to google-we...@googlegroups.com
Hi,
Yeah i have added this listener see the code,

 Event.addNativePreviewHandler(new NativePreviewHandler() {
       @Override
       public void onPreviewNativeEvent(NativePreviewEvent event) {
           if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE) {
               if (event.getNativeEvent().getEventTarget() != null) {
                   Element as = Element.as(event.getNativeEvent().getEventTarget());
                   boolean readOnly = as.getPropertyBoolean("readOnly");
                   boolean contentEditable = as.getPropertyBoolean("isContentEditable");
                   if (readOnly || !contentEditable) {
                       event.getNativeEvent().stopPropagation();
                       event.getNativeEvent().preventDefault();
                   }
               }

           }
       }
   });

Backspace issue is solved but one more issue its creating in IE.The error message says "
  • Make sure the web address //ieframe.dll/dnserror.htm# is correct." when i click the hyperlink(see the attched image).Thanks for your reply


On Friday, July 11, 2014 2:48:29 PM UTC+5:30, Mohammed Sameen wrote:
backspace.png

Jens

unread,
Jul 11, 2014, 8:00:34 AM7/11/14
to google-we...@googlegroups.com
Once the dialog box is appear that time unfortunately the user click the backspace which causes apps to exit..I need to handle this...any suggestion...

If you use the GWT DialogBox, have you tried setting it to a modal dialog box? 

-- J.

Mohammed Sameen

unread,
Jul 11, 2014, 8:13:52 AM7/11/14
to google-we...@googlegroups.com
Yes,Thanks jens got it....


On Friday, July 11, 2014 2:48:29 PM UTC+5:30, Mohammed Sameen wrote:

Mohammed Sameen

unread,
Jul 14, 2014, 7:32:10 AM7/14/14
to google-we...@googlegroups.com
Thanks for your reply  i solved by using the below snippet code
History.newItem("x");
History.addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
String historyToken = event.getValue();
            if (!historyToken.equals("X"))
             History.newItem("X");
}
});
On Friday, July 11, 2014 2:48:29 PM UTC+5:30, Mohammed Sameen wrote:
Reply all
Reply to author
Forward
0 new messages