/* * @ngdoc fbFormInput * @name fasit.directives.#fbFormInput * @fbFormInput * * @description * Directive som skapar en div med class-namnet "form-group" och en label med tillhörande input under den. */ // Använd fb-form-input.component.ts för Angular fbDeprecatedFile('fbFormInput'); angular.module('fasit') .directive('fbFormInput', ['fbFormService', function (fbFormService:fb.IFbFormService) { 'use strict'; var link = function (scope: fb.IFbFormInputScope, element: ng.IAugmentedJQuery, attrs: any) { fbDeprecated('fbFormInput'); fbFormService.functions.preLink(scope, element, attrs); //Har problem med efterblivet internet explorer här. //Istället för att ha placeholder="{{placeholder}}" i directivet så lägger vi på //placeholdern i link. Anledningen till att vi fixar detta är att array[0].modell strular //i IE10-11 om vi inte gör såhär. var el = angular.element(element); var input = el.find('input'); input.attr('placeholder', scope.placeholder); //Lägger in readonly här istället för i templaten //eftersom grunt ersätter readonly=true till endast readonly //vilket inte plockas upp i templaten //OBS: readonly=false fungerar inte med denna lösning, finns readonly-attributet så blir den readonly if ('readonly' in scope) { input.attr('readonly', 'true'); } var focusFn = function () { element.find('input')[0].focus(); }; // IE10 stödjer inte pointer events i css-en så vi måste skicka vidare klicket manuellt. Ta bort detta då IE10 inte längre ska stödjas. element.bind('click', focusFn); scope.$on('$destroy', function () { element.unbind('click', focusFn); }); if (angular.isDefined(attrs['autofocus'])) { element.find('input')[0].focus(); } fbFormService.functions.postLink(scope, element, attrs); } var compile = function (element: fb.IRootElementService, attrs: any) { fbFormService.functions.preCompile(element, attrs); if (!attrs.name) { attrs.name = attrs.model; attrs.name = attrs.name.replace(/ /g, '-').toLowerCase(); } if (!attrs.label) { attrs.label = attrs.name; } if (attrs.adaptiveLabel === "") { attrs.adaptiveLabel = " "; } if (!angular.isDefined(attrs.type)) { attrs.type = "text"; } if (angular.isDefined(attrs.noLabel)) { attrs.noLabel = "true"; } if (!angular.isDefined(attrs.readonly)) { attrs.readonly = false; } if (angular.isDefined(attrs.maxlength)) { angular.element(element).find('input').attr('maxlength', attrs.maxlength); } fbFormService.functions.postCompile(element, attrs); return link; }; return { restrict: 'E', scope: fbFormService.getScopeObject( { label: '@', type: '@', name: '@', placeholder: '@', noLabel: '@', adaptiveLabel: '@', autofocus: '@', maxlength: '@', readonly: '@', fbType: '@' }), compile: compile, templateUrl: 'app/Directives/fbFormInput/fbFormInput.html' }; }]);