Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event on keydown #22

Closed
dubrod opened this issue Mar 28, 2016 · 2 comments
Closed

Event on keydown #22

dubrod opened this issue Mar 28, 2016 · 2 comments

Comments

@dubrod
Copy link

dubrod commented Mar 28, 2016

First, awesome plugin, i love it.

I'm doing a dynamic form bind just like your Rockstar death demo.

so i see under ui > "element" > manifest > ui there is

events: "click.my"

but it doesnt help much for keyboard accessibility. is there something we can add their for keydown events ?

i even have a jquery .keypress function listening to the list: elements so if there is some external command to bind the form that way please let me know.

Thanks!

@ermouth
Copy link
Owner

ermouth commented Mar 28, 2016

General approach of $.my is

  1. to simplify coding everyday UI cases,
  2. although keeping thing somehow flexible using declarative markup like events:[evtList],
  3. however allowing maximum flexibility using good old fashoined js code.

So as for your case – put custom bindings into init function, placed inside appropriate ui section. Like:

ui:{
  '#ctrl':{
    init: function ($ctrl) {
      var that = this;
      $ctrl.on ('somevent.my', function (evt){
         // Set some filed in data to 1;
         that.data.doc.otherField = 1;
         // Trigger recalc on some other control
         that.my.trigger ('#someOtherCtrl', 'recalc');
      });
    },
    bind:'doc.field'
  }
}

Here your control reacts by default and puts/gets its value into doc.field when default event happens, although on custom event control does something completely different.

Note, that syntax somevent.my with .my namespace guarantees your handler will be automatically unbound on form destroy.

@dubrod
Copy link
Author

dubrod commented Mar 28, 2016

i wish i could say that was the solution but i didnt really understand it.
It was helpful though

It did cause me to rethink the manual trigger i put in.

I had it looking to the parent b/c the parent had a "manifest ID" i think you call it. but looking at the init you are placing on #ID i re-triggered the keydown for it.

so...

.... if (e.keyCode == 13) {
var target = $(this).children("#id");
target.trigger("click");
}

and it loads the form just like a click.

@dubrod dubrod closed this as completed Mar 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants