UNPKG

ng-jhipster

Version:

A Jhipster util library for Angular 2

32 lines (31 loc) 1.53 kB
import { Directive, ElementRef, Renderer } from '@angular/core'; export var ShowValidationDirective = (function () { function ShowValidationDirective(el, renderer) { var formElements = el.nativeElement.querySelectorAll('.form-group'); Array.prototype.forEach.call(formElements, function (formGroup) { // TODO this needs to be properly tested var inputs = formGroup.querySelectorAll('input[(ngModel)],textarea[(ngModel)],select[(ngModel)]'); if (inputs !== null) { Array.prototype.forEach.call(inputs, function (input) { // TODO this logic needs to be checked and fixed accordingly var isInvalid = input.classList.contains('ng-invalid') && input.classList.contains('ng-dirty'); formGroup.classList.toggle('has-error', isInvalid); /*scope.$watch(function() { return $input.hasClass('ng-invalid') && $input.hasClass('ng-dirty'); }, function(isInvalid) { $formGroup.toggleClass('has-error', isInvalid); });*/ }); } }); } ShowValidationDirective.decorators = [ { type: Directive, args: [{ selector: 'form[jhiShowValidation]' },] }, ]; /** @nocollapse */ ShowValidationDirective.ctorParameters = function () { return [ { type: ElementRef, }, { type: Renderer, }, ]; }; return ShowValidationDirective; }());