import angular from 'angular' angular.module('app').directive('mflyTextinput', ['translateFactory', function mflyTextinput(translateFactory) { return { restrict: 'E', scope: { allowInvalidModel: '@', autoFocus: '@', inputId: '@', inputType: '@', isDisabled: '=', onBlur: '&', onChange: '&', onClick: '&', onEnter: '&', pattern: '<', patternErrorMessage: '<', patternValidMessage: '<', placeholder: '@', required: '@', value: '=' }, template: require('./textinput.html'), link($scope: ScopeKeyValuePair) { if ($scope.inputType === undefined) { $scope.inputType = 'text' } $scope.requiredText = translateFactory.instant('JSUI.REQUIRED') $scope.mustBeNumberText = translateFactory.instant('JSUI.MUST_BE_NUMBER') $scope.mustBeValidUrl = translateFactory.instant('JSUI.MUST_BE_VALID_URL') $scope.inputWasBlurred = function() { $scope.onBlur({ value: $scope.value }) } $scope.inputWasClicked = function() { $scope.onClick() } $scope.keyWasPressed = function($event) { if ($event.keyCode === 13) { // Enter $scope.onEnter() } } $scope.valueWasChanged = function(value) { $scope.onChange({ value }) } } } }])