Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Custom Widget: how to filter keys ?
Custom Widget: how to filter keys ? [message #1778197] Mon, 11 December 2017 18:42 Go to next message
Michel R is currently offline Michel RFriend
Messages: 46
Registered: April 2015
Member
Hello,

I need to finely control what is typed in a field, for instance only some specific digits.

I implemented a custom widget, so far it works, but I can't block unauthorized characters before they are displayed in the field, only afterwards in the _onFieldInput method where I can remove them. This result in the character to be displayed, then immediately removed, from the field.

I would like to avoid this, and just block the character before it is displayed. I tried to understand what 'KeyStrokeContext' does but I don't get it, whatever I try doesn't work, the key event is processed by my KeyStrokeContext object but in the end it is always displayed in the field.

What should I do ?

Thank you.
Michel
Re: Custom Widget: how to filter keys ? [message #1778236 is a reply to message #1778197] Tue, 12 December 2017 08:41 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
I assume you have a plain HTML input field in your custom widget somewhere?

I guess your problem is, that displaying a character in an input field when a key has been pressed, is default behavior of the _browser_. Where the KeyStrokeContext is a Scout concept, which is used later in the chain of events.

When you like to prevent default behavior of the browser, you usually add an event-listener and call preventDefault() or return false in the event handler. Additionally you must know which browser-event you must prevent in order to prevent a default browser action. In your case it's probably the the onkeydown event.

See: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

There's some example code for how to prevent an input event for certain characters, see "checkName".


Eclipse Scout Homepage | Documentation | GitHub
Re: Custom Widget: how to filter keys ? [message #1778294 is a reply to message #1778236] Tue, 12 December 2017 17:13 Go to previous message
Michel R is currently offline Michel RFriend
Messages: 46
Registered: April 2015
Member
Thank you Andre. I understand a little more how this works. I thought that the scout widget (StringWidget) was processing the character keys but it doesn't, the key is just passed in the end to the "default action" which actually does the field update. This really helps.
Previous Topic:MySQL issue ArithmeticException: / by zero
Next Topic:Checkbox of checkable table disappearing
Goto Forum:
  


Current Time: Wed Apr 24 19:36:32 GMT 2024

Powered by FUDForum. Page generated in 0.03399 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top