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
2016-09-15 13:25:57 -04:00

39 lines
No EOL
950 B
JavaScript

/**
* 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);
}
};
});