29 lines
630 B
JavaScript
29 lines
630 B
JavaScript
|
'use strict';
|
||
|
|
||
|
angular.module('forms').directive('keyToOption', function(){
|
||
|
return {
|
||
|
restrict: 'A',
|
||
|
scope: {
|
||
|
field: '='
|
||
|
},
|
||
|
link: function($scope, $element, $attrs) {
|
||
|
$element.bind('keydown keypress', function(event) {
|
||
|
console.log('keypress');
|
||
|
|
||
|
var keyCode = event.which || event.keyCode;
|
||
|
var index = parseInt(String.fromCharCode(keyCode))-1;
|
||
|
console.log($scope.field);
|
||
|
|
||
|
|
||
|
if (index < $scope.field.fieldOptions.length) {
|
||
|
event.preventDefault();
|
||
|
$scope.$apply(function () {
|
||
|
$scope.field.fieldValue = $scope.field.fieldOptions[index].option_value;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
});
|