tellform/public/modules/forms/directives/key-to-truthy.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

31 lines
763 B
JavaScript

'use strict';
angular.module('forms').directive('keyToTruthy', ['$rootScope', function($rootScope){
return {
restrict: 'A',
scope: {
field: '='
},
link: function($scope, $element, $attrs) {
$element.bind('keydown keypress', function(event) {
var keyCode = event.which || event.keyCode;
var truthyKeyCode = $attrs.keyCharTruthy.charCodeAt(0) - 32;
var falseyKeyCode = $attrs.keyCharFalsey.charCodeAt(0) - 32;
if(keyCode === truthyKeyCode ) {
event.preventDefault();
$scope.$apply(function() {
$scope.field.fieldValue = 'true';
});
}else if(keyCode === falseyKeyCode){
event.preventDefault();
$scope.$apply(function() {
$scope.field.fieldValue = 'false';
});
}
});
}
};
}]);