2016-05-14 01:55:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('forms').directive('keyToOption', function(){
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
scope: {
|
|
|
|
field: '='
|
|
|
|
},
|
|
|
|
link: function($scope, $element, $attrs) {
|
|
|
|
$element.bind('keydown keypress', function(event) {
|
|
|
|
|
|
|
|
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;
|
2016-05-20 04:38:05 +00:00
|
|
|
if($attrs.type === 'dropdown'){
|
|
|
|
//$select.selected.option_value = $scope.field.fieldOptions[index].option_value;
|
|
|
|
}
|
|
|
|
console.log($scope);
|
2016-05-14 01:55:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|