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/ui/regex-editor.js

39 lines
950 B
JavaScript
Raw Normal View History

2019-11-12 16:09:47 +00:00
/**
* An element which displays an edit box for regular expressions.
*/
angular.module('quay').directive('regexEditor', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/regex-editor.html',
replace: false,
transclude: true,
restrict: 'C',
scope: {
'placeholder': '@placeholder',
'optional': '=optional',
'binding': '=binding'
},
controller: function($scope, $element) {
}
};
return directiveDefinitionObject;
});
angular.module('quay').directive('requireValidRegex', function() {
return {
require: 'ngModel',
link: function(scope, element, attr, ctrl) {
function validator(value) {
try {
new RegExp(value)
ctrl.$setValidity('regex', true);
} catch (e) {
ctrl.$setValidity('regex', false);
}
return value;
}
ctrl.$parsers.push(validator);
}
};
});