/* Provides validation messages and styling with AngularJS and Bootstrap. Example usage:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. For more information, please refer to */ (function () { "use strict"; angular.module('my-module').directive('myValidate', function () { return { restrict: 'A', require: '^form', link: function(scope, element, attrs, form) { var formGroup = element[0]; var inputElement = formGroup.querySelector('.form-control[name]'); if (!inputElement) { throw "Cannot find required .form-control[name]"; } var ngHelpText = angular.element(""); angular.element(formGroup).append(ngHelpText); scope.$watch(function () { if (form[inputElement.name].$invalid && (form[inputElement.name].$dirty || form.$submitted)) { angular.element(formGroup).addClass('has-error'); ngHelpText.show(); } else { angular.element(formGroup).removeClass('has-error'); ngHelpText.hide(); } }); } } }); })();