Add regex validating field
This commit is contained in:
parent
c4eaed186e
commit
949dcb9d35
4 changed files with 50 additions and 3 deletions
39
static/js/directives/ui/regex-editor.js
Normal file
39
static/js/directives/ui/regex-editor.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
};
|
||||
});
|
Reference in a new issue