0

MVVM and Listening for Keyboard events [closed]

asked 2012-04-19 22:33:15 +0800

rdgrimes gravatar image rdgrimes
735 7

I've gone through all the ZK documentation that I could find on listening for keyboard events, such as ENTER. But, all those solutions suppose an MVC approach with a Composer bound to the view. So, I'm a bit lost as to how to implement a listener in the MVVM architecture so that, if the user hits ENTER in any form textbox, it will behave as if the the button had been clicked and thereby execute the associated button's onClick @Command.

Thanks for any help.

Ron

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by rdgrimes
close date 2013-01-26 03:20:36

3 Replies

Sort by ยป oldest newest

answered 2012-10-25 18:05:48 +0800

elefa gravatar image elefa
21

Capture Enter key in all controls in hlayout and send 'command' command:

<hlayout forward="onOK=btn.onClick">
   <textbox/>
   <combobox/>
   <checkbox/>
</hlayout>
<button id="btn" label="btn" onClick="@command('command')"/>

link publish delete flag offensive edit

answered 2012-04-20 09:16:58 +0800

Matze2 gravatar image Matze2
773 7

Just some ideas:

ENTER usually raises onOK, you could bind your command to it

onOK="@command('cmd')"

But if you click the button, your textbox loses focus so also the onChange event is raised. This means, you probably need to simulate that, too, e.g. with
forward="onOk=onChange"

but this could interfere with the command binding above.

Please post your final solution. I'm interested in that, too.

link publish delete flag offensive edit

answered 2012-04-20 14:50:53 +0800

rdgrimes gravatar image rdgrimes
735 7

Thanks. Yes, I had found that the onOK event can be used on textbox, but it was my understanding (pre MVVM), one could set up a keylistener on the entire form. It looks like we now (under MVVM) have to have an onOK event coded on every form input field, which seems a bit ridiculous just to capture the ENTER key. Plus, I don't know why the ZK team thought they would break convention of using keyup and keydown listeners and go with onOK, which implies someone has click the OK button on a modal window. It's not very intuitive.

I'll post back if I find a better solution.

link publish delete flag offensive edit

Question tools

Follow

RSS

Stats

Asked: 2012-04-19 22:33:15 +0800

Seen: 427 times

Last updated: Oct 25 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More