keydown versus keypressed

Hello,
After a long while i’ve decided to dive in to the “web”-possibilities of xojo
I’m looking for a way to have the “keydown” possibilities in the “keypressed” event.
Basically i want a searchfield to filter on numbers only.
The key pressed doesn’t return a boolean, so i’m stuck.

Any help?

you can’t do that as key events in web edition are asynchronously.

There is the “Type” property on text fields to restrict entry to numbers, but it’s only supported on certain HTML5 compliant browsers.

The usual way to handle this in WE is to check the input in the TextChanged event and notify the user if not valid. In your case, you could automatically strip all non-numeric characters (but still notify the user).

You could use

MyTextField.text.val

as it returns the numeric value of the field or

MyNumericValue= MyTextField.Text.ReplaceAll("$","").ReplaceAll(",","").Val

This one, for example, strips down the $ and , out of a field where people will be typing currency values.

[quote=43013:@Stefaan Gouwy]Hello,
After a long while i’ve decided to dive in to the “web”-possibilities of xojo
I’m looking for a way to have the “keydown” possibilities in the “keypressed” event.
Basically i want a searchfield to filter on numbers only.
The key pressed doesn’t return a boolean, so i’m stuck.

Any help?[/quote]
The problem with trying to do things in the key pressed event is that the event gets sent to the server, your app does some processing, and then but the time the response is sent back the user may have typed a lot more or clicked somewhere else.
And doing things in key pressed events can send a LOT of traffic back & forth which can affect overall performance.

Can’t these things be handled by some custom javascript code client-side?

Don’t forget the logic of the application resides on the server side and if there is custom processing to be done that’s where it occurs.

Say you want to filter available names in a combo box based on key presses
And the list comes from a database on the back end

That cannot be handled all on the client side

[quote=43045:@Andres Montoya]You could use

MyTextField.text.val

as it returns the numeric value of the field[/quote]
That only works for strings that begin with a number, and it only processes digits up to the first non-digit character.

[quote=43057:@Norman Palardy]Say you want to filter available names in a combo box based on key presses.
… That cannot be handled all on the client side[/quote]
Right. But I was referring to the original question: Filtering input in a text field. There, a client-side javascript filter should help, shouldn’t it?

You might be able to ignore certain keys outright
But anything that could affect how your app responds to keys has to go to the app running on the server