Custom Widget: how to filter keys ? [message #1778197] |
Mon, 11 December 2017 18:42 |
Michel R 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 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02427 seconds