How to use the @angular/forms.Validators.nullValidator 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 bwsw / cloudstack-ui / src / app / shared / directives / forbidden-values.directive.ts View on Github external
import { Directive, Input, OnInit } from '@angular/core';
import { FormControl, NG_VALIDATORS, Validator, Validators } from '@angular/forms';
import { forbiddenValuesValidator } from './forbidden-values-validator';

@Directive({
  // tslint:disable-next-line
  selector: '[forbiddenValues]',
  providers: [{ provide: NG_VALIDATORS, useExisting: ForbiddenValuesDirective, multi: true }],
})
export class ForbiddenValuesDirective implements OnInit, Validator {
  @Input()
  public forbiddenValues: string[];
  private validator = Validators.nullValidator;

  public ngOnInit(): void {
    this.validator = forbiddenValuesValidator(this.forbiddenValues);
  }

  public validate(c: FormControl): { [key: string]: any } {
    return this.validator(c);
  }
}
github intershop / intershop-pwa / src / app / shared / forms / containers / login-form / login-form.container.ts View on Github external
ngOnInit() {
    this.loginError$ = this.accountFacade.userError$;

    const loginValidator = this.loginType === 'email' ? CustomValidators.email : Validators.nullValidator;

    this.form = new FormGroup({
      login: new FormControl('', [Validators.required, loginValidator]),
      password: new FormControl('', Validators.required),
    });
  }
github goharbor / harbor / src / ui_ng / src / app / shared / target-exists-directive.ts View on Github external
ngOnChanges(changes: SimpleChanges): void {
    const change = changes['targetExists'];
    if (change) {
      const target: string = change.currentValue;
      this.valFn = this.targetExistsValidator(target);
    } else {
      this.valFn = Validators.nullValidator;
    }
  }
  validate(control: AbstractControl): {[key: string]: any} {
github goharbor / harbor / src / portal / src / lib / components / datetime-picker / date-validator.directive.ts View on Github external
validate(control: AbstractControl): { [key: string]: any } {
    return this.valFn(control) || Validators.nullValidator;
  }
}
github ngx-meta / rules / libs / fiori-rules / src / lib / ui / form / form-field / form-field.component.ts View on Github external
/**
   * When used as standalone without form-group you can set FormGroup, otherwise it is set from
   * parent
   */
  @Input() get formGroup(): FormGroup {
    return this._formGroup;
  }

  set formGroup(value: FormGroup) {
    this._formGroup = value;
    this.initFormControl();
    this._cd.markForCheck();
  }

  @Input()
  validators: Array = [Validators.nullValidator];

  @Input()
  rank: number;

  @Input()
  placeholder: string;

  @Input()
  fluid: boolean = false;

  /**
   * This is in most of the cases set from parent container (form-group)
   */
  @Input()
  i18Strings: TemplateRef;
github goharbor / harbor / src / portal / src / app / shared / target-exists-directive.ts View on Github external
import { Observable } from 'rxjs';
import { ProjectDefaultService, ProjectService } from "../../lib/services";

@Directive({
  selector: '[targetExists]',
  providers: [
     MemberService,
    { provide: ProjectService, useClass: ProjectDefaultService },
    { provide: NG_ASYNC_VALIDATORS, useExisting: TargetExistsValidatorDirective, multi: true },
  ]
})
export class TargetExistsValidatorDirective implements Validator, OnChanges {
  @Input() targetExists: string;
  @Input() projectId: number;

  valFn = Validators.nullValidator;

  constructor(
    private projectService: ProjectService,
    private memberService: MemberService) { }

  ngOnChanges(changes: SimpleChanges): void {
    const change = changes['targetExists'];
    if (change) {
      const target: string = change.currentValue;
      this.valFn = this.targetExistsValidator(target);
    } else {
      this.valFn = Validators.nullValidator;
    }
  }
  validate(control: AbstractControl): { [key: string]: any } {
    return this.valFn(control);
github Squidex / squidex / frontend / app / framework / angular / forms / editable-title.component.ts View on Github external
public set isRequired(value: boolean) {
        const validator =
            value ?
            Validators.required :
            Validators.nullValidator;

        this.renameForm.controls['name'].setValidators(validator);
    }
github Squidex / squidex / frontend / app / features / administration / state / users.forms.ts View on Github external
public load(value: Partial) {
        if (value) {
            this.form.controls['password'].setValidators(Validators.nullValidator);
        } else {
            this.form.controls['password'].setValidators(Validators.required);
        }

        super.load(value);
    }
github vmware / flowgate / ui / src / app / pages / facility / component / cmdb / cmdb-edit / cmdb-edit.component.ts View on Github external
checkIsLabsDB(){
    this.cmdbForm.setControl("userName",new FormControl('',Validators.required));
    this.cmdbForm.setControl("passwordInput",new FormControl('',Validators.required));
    if(this.cmdbConfig.type == "Labsdb"){
      this.cmdbForm.setControl("userName",new FormControl('',Validators.nullValidator));
      this.cmdbForm.setControl("passwordInput",new FormControl('',Validators.nullValidator));
    }else if(this.cmdbConfig.type == "InfoBlox"){
      this.isInfoblox = true;
      if(this.cmdbConfig.advanceSetting != null && this.cmdbConfig.advanceSetting.INFOBLOX_PROXY_SEARCH != ""){
        this.enableProxySearch = true;
        this.advanceSetting = this.cmdbConfig.advanceSetting;
      }
    }
  }
github inspursoft / board / src / ui / src / app / shared / directives / check-item-existing.directive.ts View on Github external
import 'rxjs/add/operator/map'
import { HttpClient } from '@angular/common/http';
import { AppInitService } from '../../app.init.service';
import { MessageService } from '../message-service/message.service';

@Directive({
  selector: '[checkItemExisting]',
  providers: [
    {provide: NG_ASYNC_VALIDATORS, useExisting: CheckItemExistingDirective, multi: true}
  ]
})
export class CheckItemExistingDirective implements AsyncValidator {
  @Input() checkItemExisting;
  @Input() userID: number = 0;

  valFn: ValidatorFn = Validators.nullValidator;

  constructor(private http: HttpClient,
              private appInitService: AppInitService,
              private messageService: MessageService) {
  }

  checkUserExists(target: string, value: string, userID: number): Observable<{[key: string]: any}> {
    return this.http.get("/api/v1/user-exists", {
      observe: "response",
      params: {
        'target': target,
        'value': value,
        'user_id': userID.toString()
      }
    })
    .map(()=>this.valFn)