2016-05-14 01:55:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('forms').directive('keyToOption', function(){
|
|
|
|
return {
|
2016-05-20 19:41:18 +00:00
|
|
|
restrict: 'AE',
|
|
|
|
transclude: true,
|
2016-05-14 01:55:48 +00:00
|
|
|
scope: {
|
2016-05-20 19:41:18 +00:00
|
|
|
field: '&'
|
2016-05-14 01:55:48 +00:00
|
|
|
},
|
2016-05-20 19:41:18 +00:00
|
|
|
link: function($scope, $element, $attrs, $select) {
|
2016-05-14 01:55:48 +00:00
|
|
|
$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'){
|
2016-05-20 19:41:18 +00:00
|
|
|
$select.selected.option_value = $scope.field.fieldOptions[index].option_value;
|
2016-05-20 04:38:05 +00:00
|
|
|
}
|
|
|
|
console.log($scope);
|
2016-05-14 01:55:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|