This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/match.js

16 lines
459 B
JavaScript
Raw Normal View History

2019-11-12 16:09:47 +00:00
/**
* Adds a 'match' attribute that ensures that a form field's value matches another field's
* value.
*/
angular.module('quay').directive('match', function($parse) {
return {
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
scope.$watch(function() {
return $parse(attrs.match)(scope) === ctrl.$modelValue;
}, function(currentValue) {
ctrl.$setValidity('mismatch', currentValue);
});
}
};
});