aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/form-elements/validation/validators
diff options
context:
space:
mode:
Diffstat (limited to 'src/angular/form-elements/validation/validators')
-rw-r--r--src/angular/form-elements/validation/validators/base.validator.component.html.ts10
-rw-r--r--src/angular/form-elements/validation/validators/base.validator.component.ts25
-rw-r--r--src/angular/form-elements/validation/validators/custom.validator.component.ts23
-rw-r--r--src/angular/form-elements/validation/validators/regex.validator.component.ts24
-rw-r--r--src/angular/form-elements/validation/validators/required.validator.component.ts25
-rw-r--r--src/angular/form-elements/validation/validators/validator.interface.ts3
6 files changed, 110 insertions, 0 deletions
diff --git a/src/angular/form-elements/validation/validators/base.validator.component.html.ts b/src/angular/form-elements/validation/validators/base.validator.component.html.ts
new file mode 100644
index 0000000..aba8eed
--- /dev/null
+++ b/src/angular/form-elements/validation/validators/base.validator.component.html.ts
@@ -0,0 +1,10 @@
+export default `
+<svg-icon-label
+ *ngIf="!isValid"
+ name="alert-triangle"
+ mode="error"
+ size="small"
+ [label]="message"
+ labelPlacement="right">
+</svg-icon-label>
+`;
diff --git a/src/angular/form-elements/validation/validators/base.validator.component.ts b/src/angular/form-elements/validation/validators/base.validator.component.ts
new file mode 100644
index 0000000..3d751af
--- /dev/null
+++ b/src/angular/form-elements/validation/validators/base.validator.component.ts
@@ -0,0 +1,25 @@
+import { Input, Component, ContentChildren, EventEmitter, Output, QueryList, SimpleChanges, HostBinding } from "@angular/core";
+import { IValidator } from './validator.interface';
+import template from "./base.validator.component.html";
+
+@Component({
+ selector: 'sdc-validator',
+ template: template
+})
+export abstract class ValidatorComponent {
+
+ @Input() public message: any;
+ @Input() public disabled: boolean;
+ @HostBinding('class') classes;
+
+ protected isValid: boolean;
+
+ constructor() {
+ this.disabled = false;
+ this.isValid = true;
+ this.classes = 'sdc-validator sdc-label__error';
+ }
+
+ public abstract validate(value: any): boolean;
+
+}
diff --git a/src/angular/form-elements/validation/validators/custom.validator.component.ts b/src/angular/form-elements/validation/validators/custom.validator.component.ts
new file mode 100644
index 0000000..eb09636
--- /dev/null
+++ b/src/angular/form-elements/validation/validators/custom.validator.component.ts
@@ -0,0 +1,23 @@
+import { Input, Component } from "@angular/core";
+import { ValidatorComponent } from "./base.validator.component";
+import { IValidator } from './validator.interface';
+import template from "./base.validator.component.html";
+
+@Component({
+ selector: 'sdc-custom-validator',
+ template: template
+})
+export class CustomValidatorComponent extends ValidatorComponent implements IValidator {
+
+ @Input() public callback: (...args) => boolean;
+
+ constructor() {
+ super();
+ }
+
+ public validate(value: any): boolean {
+ this.isValid = this.callback(value);
+ return this.isValid;
+ }
+
+}
diff --git a/src/angular/form-elements/validation/validators/regex.validator.component.ts b/src/angular/form-elements/validation/validators/regex.validator.component.ts
new file mode 100644
index 0000000..5929016
--- /dev/null
+++ b/src/angular/form-elements/validation/validators/regex.validator.component.ts
@@ -0,0 +1,24 @@
+import { Input, Component } from "@angular/core";
+import { ValidatorComponent } from "./base.validator.component";
+import { IValidator } from './validator.interface';
+import template from "./base.validator.component.html";
+
+@Component({
+ selector: 'sdc-regex-validator',
+ template: template
+})
+export class RegexValidatorComponent extends ValidatorComponent implements IValidator {
+
+ @Input() public pattern: RegExp;
+
+ constructor() {
+ super();
+ }
+
+ public validate(value: any): boolean {
+ const regexp = new RegExp(this.pattern);
+ this.isValid = regexp.test(value);
+ return this.isValid;
+ }
+
+}
diff --git a/src/angular/form-elements/validation/validators/required.validator.component.ts b/src/angular/form-elements/validation/validators/required.validator.component.ts
new file mode 100644
index 0000000..7eee932
--- /dev/null
+++ b/src/angular/form-elements/validation/validators/required.validator.component.ts
@@ -0,0 +1,25 @@
+import { Input, Component } from "@angular/core";
+import { ValidatorComponent } from "./base.validator.component";
+import { IValidator } from './validator.interface';
+import template from "./base.validator.component.html";
+
+@Component({
+ selector: 'sdc-required-validator',
+ template: template
+})
+export class RequiredValidatorComponent extends ValidatorComponent implements IValidator {
+
+ constructor() {
+ super();
+ }
+
+ public validate(value: any): boolean {
+ if (value) {
+ this.isValid = true;
+ } else {
+ this.isValid = false;
+ }
+ return this.isValid;
+ }
+
+}
diff --git a/src/angular/form-elements/validation/validators/validator.interface.ts b/src/angular/form-elements/validation/validators/validator.interface.ts
new file mode 100644
index 0000000..c0adc24
--- /dev/null
+++ b/src/angular/form-elements/validation/validators/validator.interface.ts
@@ -0,0 +1,3 @@
+export interface IValidator {
+ validate(value: any): void;
+}