Created
September 22, 2014 14:04
-
-
Save neilbo/69ec1ba325044711228c to your computer and use it in GitHub Desktop.
Show an error when inputs match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.help-block { | |
display: none; | |
} | |
.has-error .help-block { | |
display: block; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="myForm"> | |
<input name="mobile1" ng-model="mobile.first" /> | |
<input name="mobile2" ng-model="mobile.second" /> | |
<p ng-if="myForm.mobile2.$error.mismatch && myForm.mobile2.$dirty" class="help-block">First Mobile and Second Mobile must NOT match.</p> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myapp') | |
.directive('notmatch', function($parse) { | |
return { | |
require: 'ngModel', | |
link: function(scope, elem, attrs, ctrl) { | |
scope.$watch(function() { | |
return $parse(attrs.notmatch)(scope) === ctrl.$modelValue; | |
}, function(currentValue) { | |
ctrl.$setValidity('mismatch', !currentValue); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment