Textbox KeyPressEventHandler e.Handled = true doesn't work

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
0
0

Textbox works fine, but if I try to cancel some char input with

e.Handled = true

it doesn’t work.

Can I handle events inside objects with JavaScript?

  • You must to post comments
0
0

Hello Takashi,

Keyboard events, like all events in Wisej, are routed to the server asynchronously. The Handled property is useful on the server side when managing the OnKeyDown/Up/Press events to signal that a child has handled the key. However, this has no effect on the client,  unless you actually change the Text property to trigger a client update – I wouldn’t recommend this approach unless really necessary.

If you want to handle keys as they are typed and be able to stop the browser from processing the key you have to do it on the client using the JavaScript provider. It’s quite easy with Wisej. I have attached a sample project for you to use as a reference and a screen shot below of the script editor.

Download the sample

 

 

  • Drop the JavaScript component on the page or window. This will add the JavaScript and JavaScriptSource property to all controls.
  • You can either type the javascript code in JavaScript, or select a .js file in JavaScriptSource.
  • The javascript runs in the widget’s context: this = widget, see code above. It runs only once when  the page is loaded or reloaded.

Keeping the script above as a reference, we attach the “keypress” handler and handle the event. To stop it from both bubbling and “defaulting” use e.stop(). Otherwise you can use e.stopBubbling() and e.preventDefault().

When you work directly in javascript we enter the qooxdoo realm. The full API is here: http://demo.qooxdoo.org/current/apiviewer/#qx

 

  • ITG Admin
    I’d like to add that in Wisej there are other ways to invoke javascript from the server in addition to the JavaScript provider. You can call Invoke() on any control and pass either a full script or a function name and arguments. See the overloads. The script always runs in the context of the control you invoked it on: “this” refers to the javascript widget. i.e. this.button1.Invoke(“hide”) will hide the client representation of the button. Scripts are always run last in the request/response cycle. There is also a web method callback system from JavaScript – call the server from the client marking an *instance* method [WebMethod] – and Wisej builds an entire object model on the client side under window.App. But this is a topic for the documentation and an example.
  • You must to post comments
0
0

Thanks Takashi,

we have logged this bug in our tracking system as WJ-7225.
We will post a new answer here when it is resolved.

  • You must to post comments
Showing 2 results
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 5, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json