How to detect "Space" key in treecontrol in AngularJS

297 views Asked by At

I have a problem with treecontrol from angular-ui for AngularJS in version 1.5. Treecontrol has directive called on-selection which detects "Enter" or mouse click and send option from treecontrol to input. I want the same behaviour for "Space" key, but I don't know how to add it to treecontrol. Also, normal ng-keypress doesn't work. I can't modify any angular-ui files. Anyone knows solution for that issue?

Edit: Code:

template: '<div class="autocomplete"><treecontrol class="tree-light" tree-model="source" options="ctrl.treeOptions" filter-expression="filter" expanded-nodes="expandedNodes" on-selection="nodeSelect(node)" ng-keypress="spaceClicked($event)">' +
          '<span><i class="enms enms-{{node.type}}"></i>{{node.name | translate}}</span></treecontrol></div>',
link: function(scope, elem, attrs, ctrl) {
    this.ctrl = ctrl;

    scope.nodeSelect = function (node) {
    // Element selektieren
    scope.onSelect()(node);
};

scope.spaceClicked = function (event) {
     console.log("Clicked: ");
     console.log(event.keyCode);
};

Live example: Screen 1: enter image description here

Screen 2: enter image description here

When user starts type anything in input, treecontrol will appear and show matched options (Screen 1). Now user needs to click with mouse on option or click "Enter" button to add option to input (Screen 2). I want to get the same behavior for "Space" key also. I hope that now my problem is clear :)

0

There are 0 answers