summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/directives/invalid-characters/invalid-characters.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/directives/invalid-characters/invalid-characters.ts')
-rw-r--r--catalog-ui/src/app/directives/invalid-characters/invalid-characters.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/catalog-ui/src/app/directives/invalid-characters/invalid-characters.ts b/catalog-ui/src/app/directives/invalid-characters/invalid-characters.ts
new file mode 100644
index 0000000000..20ed71e53f
--- /dev/null
+++ b/catalog-ui/src/app/directives/invalid-characters/invalid-characters.ts
@@ -0,0 +1,51 @@
+'use strict';
+
+export class InvalidCharactersDirective implements ng.IDirective {
+
+ constructor() {
+ }
+
+ require = 'ngModel';
+
+ link = (scope, elem, attrs, ngModel) => {
+
+ let invalidCharacters = [];
+
+ attrs.$observe('invalidCharacters', (val:string) => {
+ invalidCharacters = val.split('');
+ validate(ngModel.$viewValue);
+ });
+
+ let validate:Function = function (value) {
+
+ let valid:boolean = true;
+
+ if (value) {
+ for (let i = 0; i < invalidCharacters.length; i++) {
+ if (value.indexOf(invalidCharacters[i]) != -1) {
+ valid = false;
+ }
+ }
+ }
+
+ ngModel.$setValidity('invalidCharacters', valid);
+ if (!value) {
+ ngModel.$setPristine();
+ }
+ return value;
+ };
+
+ //For DOM -> model validation
+ ngModel.$parsers.unshift(validate);
+ //For model -> DOM validation
+ ngModel.$formatters.unshift(validate);
+
+ };
+
+ public static factory = ()=> {
+ return new InvalidCharactersDirective();
+ };
+
+}
+
+InvalidCharactersDirective.factory.$inject = [];