Add regex validating field
This commit is contained in:
parent
c4eaed186e
commit
949dcb9d35
4 changed files with 50 additions and 3 deletions
|
@ -39,9 +39,10 @@
|
|||
</select>
|
||||
|
||||
<!-- Regular expression -->
|
||||
<input type="text" class="form-control" ng-model="currentConfig[field.name]" ng-switch-when="regex"
|
||||
placeholder="{{ field.placeholder || '' }}"
|
||||
ng-required="!field.optional">
|
||||
<div ng-switch-when="regex">
|
||||
<div class="regex-editor" placeholder="{{field.placeholder || '' }}"
|
||||
binding="currentConfig[field.name]" optional="field.optional"></div>
|
||||
</div>
|
||||
|
||||
<!-- Value description -->
|
||||
<div class="co-alert co-alert-info"
|
||||
|
|
4
static/directives/regex-editor.html
Normal file
4
static/directives/regex-editor.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
<div class="regex-editor-element">
|
||||
<input name="regexField" type="text" class="form-control" ng-model="binding" placeholder="{{ placeholder || '' }}"
|
||||
ng-required="!optional" require-valid-regex>
|
||||
</div>
|
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);
|
||||
}
|
||||
};
|
||||
});
|
|
@ -45,6 +45,7 @@ function(Config, Features, VulnerabilityService) {
|
|||
'help_text': 'An optional regular expression for matching the git branch or tag ' +
|
||||
'git ref. If left blank, the notification will fire for all builds.',
|
||||
'optional': true,
|
||||
'placeholder': '(refs/heads/somebranch)|(refs/tags/sometag)'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -60,6 +61,7 @@ function(Config, Features, VulnerabilityService) {
|
|||
'help_text': 'An optional regular expression for matching the git branch or tag ' +
|
||||
'git ref. If left blank, the notification will fire for all builds.',
|
||||
'optional': true,
|
||||
'placeholder': '(refs/heads/somebranch)|(refs/tags/sometag)'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -75,6 +77,7 @@ function(Config, Features, VulnerabilityService) {
|
|||
'help_text': 'An optional regular expression for matching the git branch or tag ' +
|
||||
'git ref. If left blank, the notification will fire for all builds.',
|
||||
'optional': true,
|
||||
'placeholder': '(refs/heads/somebranch)|(refs/tags/sometag)'
|
||||
}
|
||||
]
|
||||
}];
|
||||
|
|
Reference in a new issue