1angular.module('rain.form.validate', []).directive('formValidate', function($timeout) { 2 return { 3 restrict: 'A', 4 require: '^form', 5 link: function (scope, element, attrs, ngModel) { 6 // Find the text box element, which has the 'name' attribute 7 var inputEl = element[0].querySelector("[name]"); 8 // Convert the native text box element to an angular element 9 var inputNgEl = angular.element(inputEl); 10 // Get the name on the text box so we know the property to checkon the form controller 11 var inputName = inputNgEl.attr('name'); 12 13 // Initially hide the element with the error-label class 14 var errorLabel = null; 15 $timeout(function() { 16 inputEl = element[0].querySelector("[name]"); 17 inputNgEl = angular.element(inputEl); 18 inputName = inputNgEl.attr('name'); 19 errorLabel = element[0].querySelector(".error-label"); 20 if (errorLabel) { 21 errorLabel.style.display = 'none'; 22 errorLabel = angular.element(errorLabel); 23 } 24 25 // Apply the has-error class after the user leaves the text box 26 inputNgEl.on('blur', function() { 27 toggleErrorState(); 28 }); 29 30 inputNgEl.on('input', function() { 31 toggleErrorState(); 32 }); 33 34 inputNgEl.on('change', function() { 35 toggleErrorState(); 36 }); 37 }, 100, false); 38 39 var toggleErrorState = function() { 40 if (ngModel[inputName]) { 41 var invalid = ngModel[inputName].$invalid; 42 inputNgEl.toggleClass('has-error', invalid); 43 if (errorLabel) { 44 errorLabel.toggle(invalid); 45 } 46 } 47 }; 48 49 scope.$on('form-check-validity', function() { 50 toggleErrorState(); 51 }); 52 53 scope.$on('form-reset', function() { 54 $timeout(function() { 55 element.removeClass('has-error'); 56 }, 0, false); 57 }); 58 } 59 } 60});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.