Skip to content

Instantly share code, notes, and snippets.

@mcnilz
Created February 4, 2016 11:43

Revisions

  1. mcnilz created this gist Feb 4, 2016.
    21 changes: 21 additions & 0 deletions angular-bootstrap-form-error.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    angular.module("app")
    .directive('formError', function () {
    return {
    restrict: 'A',
    require: '^form',
    scope: {
    formError: '=formError'
    },
    link: function (scope, element, attrs, form) {
    scope.form = form;

    scope.$watchGroup([
    'form.' + scope.formError + '.$invalid',
    'form.' + scope.formError + '.$dirty',
    'form.$submitted'
    ], function (watch) {
    element.toggleClass('has-error', watch[0] && (watch[1] || watch[2]));
    });
    }
    };
    });