How to use the @angular/forms.Validators.maxLength function in @angular/forms

To help you get started, we’ve selected a few @angular/forms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heloufir / ngx-security-starter / front-end / src / app / main / account-settings / account-settings.component.ts View on Github external
this.loadingProfiles = true;
    this.profileService.find()
      .subscribe((res: PartialList) => {
        this.profiles = res.data;
        this.loadingProfiles = false;
      });
    if (!this.selectedUser.picture) {
      this.picturePreview = 'assets/images/faces/avatar.png';
    } else {
      this.picturePreview = environment.web_url + 'users/picture/' + this.selectedUser.id + '?v=' + Math.random();
    }
    // Initialize the form group object
    this.form = this._fb.group({
      email: [
        this.selectedUser ? this.selectedUser.email : '',
        [Validators.required, Validators.maxLength(255)]
      ],
      name: [
        this.selectedUser ? this.selectedUser.name : '',
        [Validators.required, Validators.maxLength(255)]
      ],
      password: [
        '',
        this.selectedUser && this.selectedUser.id ? [] : [Validators.required]
      ],
      password_confirmation: [
        '',
        this.selectedUser && this.selectedUser.id ? [] : [Validators.required]
      ]
    });
  }
github Teradata / covalent / src / platform / dynamic-forms / services / dynamic-forms.service.ts View on Github external
createValidators(config: ITdDynamicElementConfig): ValidatorFn {
    let validator: ValidatorFn;
    if (config.required) {
      validator = Validators.required;
    }
    if (config.max || config.max === 0) {
      validator = Validators.compose([validator, Validators.max(parseFloat(config.max))]);
    }
    if (config.min || config.min === 0) {
      validator = Validators.compose([validator, Validators.min(parseFloat(config.min))]);
    }
    if (config.maxLength || config.maxLength === 0) {
      validator = Validators.compose([validator, Validators.maxLength(parseFloat(config.maxLength))]);
    }
    if (config.minLength || config.minLength === 0) {
      validator = Validators.compose([validator, Validators.minLength(parseFloat(config.minLength))]);
    }
    // Add provided custom validators to the validator function
    if (config.validators) {
      config.validators.forEach((validatorConfig: ITdDynamicElementValidator) => {
        validator = Validators.compose([validator, validatorConfig.validator]);
      });
    }
    return validator;
  }
}
github eakoriakin / ionic-selectable / src / app / pages / min-max-selection / min-max-selection.ts View on Github external
constructor(
    private portService: PortService,
    private formBuilder: FormBuilder
  ) {
    this.ports = this.portService.getPorts();
    this.portsControl = this.formBuilder.control([], [
      Validators.required, Validators.minLength(1), Validators.maxLength(3)
    ]);
    this.form = this.formBuilder.group({
      ports: this.portsControl
    });
  }
github Picturepark / Picturepark.SDK.TypeScript / src / picturepark-sdk-v1-angular / projects / picturepark-sdk-v1-angular-ui / src / lib / features-module / share-content-dialog / share-content-dialog.component.ts View on Github external
protected dialogRef: MatDialogRef,
    protected injector: Injector,
    private formBuilder: FormBuilder,
    private shareService: ShareService,
    private translatePipe: TranslatePipe,
    private renderer: Renderer2
  ) {
    super(data, dialogRef, injector);

    this.selectedContent = data;

    this.sharedContentForm = this.formBuilder.group({
      share_name: new FormControl('', [
        Validators.required,
        Validators.minLength(5),
        Validators.maxLength(100),
      ]),
      recipients: this.formBuilder.array([], [ Validators.required ]),
      expire_date: new FormControl(''),
      recipientsSearch: new FormControl('')
    });
  }
github SharebookBR / sharebook-mobile / src / pages / donate / donate.ts View on Github external
setupForm() {
    this.freightOptions = Object.keys(FreightLabels)
      .map(value => {
        return {value, text: FreightLabels[value]}
      });

    this.form = this.formBuilder.group({
      title: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(200)]],
      author: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(200)]],
      categoryId: ['', [Validators.required]],
      freightOption: ['', [Validators.required]],
      imageBytes: ['', [Validators.required]],
      synopsis: ['', [Validators.maxLength(2000)]],
    });

    this.title = this.form.get('title');
    this.author = this.form.get('author');
    this.categoryId = this.form.get('categoryId');
    this.freightOption = this.form.get('freightOption');
    this.imageBytes = this.form.get('imageBytes');
    this.synopsis = this.form.get('synopsis');
  }
github aiten / CNCLib / Src / Server / ClientApp / src / app / gcode / gcode-detail / gcode-detail.component.ts View on Github external
autoScaleBorderDistX: [0.0, [Validators.required]],
        autoScaleBorderDistY: [0.0, [Validators.required]],

        penMoveType: [],
        engravePosInParameter: [false, [Validators.required]],
        engravePosUp: [0.0, [Validators.required]],
        engravePosDown: [0.0, [Validators.required]],
        moveSpeed: [0.0, [Validators.required]],
        engraveDownSpeed: [0.0],

        scaleX: [0.0],
        scaleY: [0.0],
        ofsX: [0.0],
        ofsY: [0.0],

        laserFirstOnCommand: ['', [Validators.maxLength(512)]],
        laserOnCommand: ['', [Validators.maxLength(512)]],
        laserOffCommand: ['', [Validators.maxLength(512)]],
        laserLastOffCommand: ['', [Validators.maxLength(512)]],
        laserSize: [0.0],
        laserAccDist: [0.0],

        smoothType: [],
        convertType: [],
        smoothMinAngle: [0.0],
        smoothMinLineLength: [0.0],
        smoothMaxError: [0.0],

        cutterSize: [1.0],

        imageWriteToFileName: ['', [Validators.maxLength(512)]],
        grayThreshold: [0.0],
github Crunchy-Torch / coddy / front / src / app / snippets / snippet-form / snippet-form.component.ts View on Github external
createForm() {
    this.snippetForm = this.formBuilder.group({
      title: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(140)]],
      description: ['',
        [Validators.required, Validators.minLength(10), Validators.maxLength(400)]],
      language: this.formBuilder.group({
        name: ['', Validators.required],
        version: '',
      }),
      keywords: ['', Validators.required],
      files: this.formBuilder.array([this.createFile()])
    });
  }
github Squidex / squidex / src / Squidex / app / features / administration / state / users.forms.ts View on Github external
constructor(
        formBuilder: FormBuilder
    ) {
        super(formBuilder.group({
            email: ['',
                [
                    Validators.email,
                    Validators.required,
                    Validators.maxLength(100)
                ]
            ],
            displayName: ['',
                [
                    Validators.required,
                    Validators.maxLength(100)
                ]
            ],
            password: ['',
                [
                    Validators.required
                ]
            ],
            passwordConfirm: ['',
                [
                    ValidatorsEx.match('password', 'Passwords must be the same.')