aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/form-validators/instance-validators.service.ts
blob: 3628f0b60e8d69532ec6325fb3e2f19d1cd8a8a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Injectable } from '@angular/core'
import { Validators } from '@angular/forms'
import { BuildFormValidator } from './form-validator.service'

@Injectable()
export class InstanceValidatorsService {
  readonly FROM_EMAIL: BuildFormValidator
  readonly FROM_NAME: BuildFormValidator
  readonly SUBJECT: BuildFormValidator
  readonly BODY: BuildFormValidator

  constructor () {

    this.FROM_EMAIL = {
      VALIDATORS: [ Validators.required, Validators.email ],
      MESSAGES: {
        'required': $localize`Email is required.`,
        'email': $localize`Email must be valid.`
      }
    }

    this.FROM_NAME = {
      VALIDATORS: [
        Validators.required,
        Validators.minLength(1),
        Validators.maxLength(120)
      ],
      MESSAGES: {
        'required': $localize`Your name is required.`,
        'minlength': $localize`Your name must be at least 1 character long.`,
        'maxlength': $localize`Your name cannot be more than 120 characters long.`
      }
    }

    this.SUBJECT = {
      VALIDATORS: [
        Validators.required,
        Validators.minLength(1),
        Validators.maxLength(120)
      ],
      MESSAGES: {
        'required': $localize`A subject is required.`,
        'minlength': $localize`The subject must be at least 1 character long.`,
        'maxlength': $localize`The subject cannot be more than 120 characters long.`
      }
    }

    this.BODY = {
      VALIDATORS: [
        Validators.required,
        Validators.minLength(3),
        Validators.maxLength(5000)
      ],
      MESSAGES: {
        'required': $localize`A message is required.`,
        'minlength': $localize`The message must be at least 3 characters long.`,
        'maxlength': $localize`The message cannot be more than 5000 characters long.`
      }
    }
  }
}