tellform/public/modules/forms/directives/key-to-option.client.directive.js
David Baldwynn 0dfcb0b443 got keyboard controls working for yes/no, legal statement and multiple choice
modified:   public/dist/application.js
	modified:   public/dist/application.min.js
	deleted:    public/modules/forms/directives/on-key-press.js

	modified:   public/dist/application.js
	modified:   public/dist/application.min.js
	new file:   public/modules/forms/directives/key-to-option.client.directive.js
	new file:   public/modules/forms/directives/key-to-truthy.client.directive.js
	deleted:    public/modules/forms/directives/on-key-press.client.directive.js
	modified:   public/modules/forms/views/directiveViews/field/legal.html
	modified:   public/modules/forms/views/directiveViews/field/radio.html
	modified:   public/modules/forms/views/directiveViews/field/rating.html
	modified:   public/modules/forms/views/directiveViews/field/yes_no.html
2016-05-13 18:57:27 -07:00

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;
});
}
});
}
};
});