@angular/forms#Validators TypeScript Examples

The following examples show how to use @angular/forms#Validators. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: home.component.ts    From one-platform with MIT License 6 votes vote down vote up
// upload form management
  auditUploadForm = new FormGroup({
    project: new FormControl('', [
      Validators.required,
      this.whitespaceValidator,
    ]),
    branch: new FormControl('', [
      Validators.required,
      this.whitespaceValidator,
    ]),
    buildToken: new FormControl('', [
      Validators.required,
      this.whitespaceValidator,
    ]),
  });
Example #2
Source File: login.component.ts    From homebridge-nest-cam with GNU General Public License v3.0 6 votes vote down vote up
generateForm(): void {
    this.form = new FormGroup({
      code: new FormControl('', [Validators.required, containsValidator('/')]),
    });

    // this.form.valueChanges.subscribe((value) => {
    //   // Do something here
    // });
  }
Example #3
Source File: confirm-phrase-password.component.ts    From xBull-Wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
ngOnInit(): void {
    const generateAccountStorageSnapshot = this.generateAccountQuery.getValue();
    const accountsStoreSnapshot = this.walletsQuery.getValue();

    // DO NOT USE THIS IN CASE YOU REALLY KNOW WHAT YOU ARE DOING
    const testPassword = 'thisisatestpasswordandyoushouldnotuseit';

    if (generateAccountStorageSnapshot.password !== testPassword) {
      if (generateAccountStorageSnapshot.pathType === 'new_wallet' && generateAccountStorageSnapshot.mnemonicPhrase) {
        this.form.controls
          .confirmPhrase.setValidators([Validators.required, sameValueValidator(generateAccountStorageSnapshot.mnemonicPhrase)]);
      }

      if (!accountsStoreSnapshot.globalPasswordHash && generateAccountStorageSnapshot.password) {
        this.form.controls
          .confirmPassword.setValidators([Validators.required, sameValueValidator(generateAccountStorageSnapshot.password)]);
      }
    } else {
      this.mnemonicPhraseService.getTestAccount().forEach(word => {
        this.phraseArray.push(new FormControl(word, Validators.required));
      });
      this.form.controls.confirmPassword.patchValue(testPassword);
    }
  }
Example #4
Source File: target-network-address.component.ts    From rubic-app with GNU General Public License v3.0 6 votes vote down vote up
constructor(
    private readonly blockchainAdapterService: PublicBlockchainAdapterService,
    private readonly storeService: StoreService,
    private readonly targetNetworkAddressService: TargetNetworkAddressService,
    private readonly destroy$: TuiDestroyService
  ) {
    this.address = new FormControl<string>(null, [Validators.required]);
    this.address.markAsDirty();
  }
Example #5
Source File: datasource.component.ts    From dbm with Apache License 2.0 6 votes vote down vote up
constructor(private service: DatasourceService,
              private messageService: NzMessageService,
              private translateService: TranslateService,
              private nzModalService: NzModalService,
              private datasourceJob: DatasourceJob,
              private formBuilder: FormBuilder) {
    super();
    this.validateForm = this.formBuilder.group({
      alias: [null, [Validators.required]],
      protocol: [null, [Validators.required]],
      host: [null, [Validators.required]],
      port: [null, [Validators.required]],
      username: [null, []],
      password: [null, []],
      maxTotal: [null, []],
      sshHost: [null, []],
      sshPort: [null, []],
      sshUsername: [null, []],
      sshPassword: [null, []]
    });
    this.sourceTypes = new SourceTypeConfig().getConfig();
    this.handlerGetAll();
    this.handlerResetButton();
  }
Example #6
Source File: login.component.ts    From ng-conf-2020-workshop with MIT License 6 votes vote down vote up
constructor(
    public authService: ExternalAuthService, private authentication: AuthenticationService,
    private userService: UserService, private router: Router, fb: FormBuilder
  ) {
    this.loginForm = fb.group({
      email: ['', Validators.required],
      password: ['', Validators.required],
    });
  }
Example #7
Source File: add-blog.component.ts    From Collab-Blog with GNU General Public License v3.0 6 votes vote down vote up
reactiveForm(){
      this.blogForm=this.fb.group({
        header:['', Validators.required],
        subheader:['', Validators.required],
        author:['', Validators.required],
        image:[''],
        body:['', Validators.required],
        tags:[[]]
      })
    }
Example #8
Source File: sort-code.directive.ts    From canopy with Apache License 2.0 6 votes vote down vote up
ngOnInit(): void {
    const validators = [
      Validators.required,
      Validators.pattern(/^(?:\d{6}|\d\d-\d\d-\d\d|\d\d\s\d\d\s\d\d)$/),
    ];

    if (this.ngControl.control.validator) {
      validators.push(this.ngControl.control.validator);
    }

    this.ngControl.control.setValidators(validators);
  }
Example #9
Source File: user-list.component.ts    From master-frontend-lemoncode with MIT License 6 votes vote down vote up
createEditForm() {
    this.editForm = this.fb.group({
      id: ['', Validators.required],
      login: ['', [Validators.required, Validators.minLength(6)]],
      avatar_url: ''
    });

    this.idControl = this.editForm.get('id') as FormControl;
    this.loginControl = this.editForm.get('login') as FormControl;
    this.avatarControl = this.editForm.get('avatar_url') as FormControl;
  }
Example #10
Source File: admin-product.component.ts    From mslearn-live-azure-fundamentals with MIT License 6 votes vote down vote up
constructor(dataClient: DataClient, formatter: FormattingHelpers, route: ActivatedRoute, private formBuilder: FormBuilder, private router: Router) {

    this.formatter = formatter;
    this.data = dataClient;
    this.id = route.snapshot.paramMap.get("productId");

    this.isCreateNewMode = this.id == "$new";

    this.productForm = this.formBuilder.group({
      name: ['', Validators.required],
      description: ['', Validators.required],
      category: ['', Validators.required],
      price: ['', Validators.required],
      stockUnits: ['', Validators.required],
      thumbnailImage: ['', Validators.required]
    });

    this.hasLoaded = true;
  }
Example #11
Source File: create-dialog.component.ts    From leapp with Mozilla Public License 2.0 6 votes vote down vote up
public form = new FormGroup({
    idpArn: new FormControl("", [Validators.required]),
    accountNumber: new FormControl("", [Validators.required, Validators.maxLength(12), Validators.minLength(12)]),
    subscriptionId: new FormControl("", [Validators.required]),
    tenantId: new FormControl("", [Validators.required]),
    name: new FormControl("", [Validators.required]),
    role: new FormControl("", [Validators.required]),
    roleArn: new FormControl("", [Validators.required]),
    roleSessionName: new FormControl("", [Validators.pattern("[a-zA-Z\\d\\-\\_\\@\\=\\,\\.]+")]),
    federatedOrIamRoleChained: new FormControl("", [Validators.required]),
    federatedRole: new FormControl("", [Validators.required]),
    federationUrl: new FormControl("", [Validators.required, Validators.pattern("https?://.+")]),
    secretKey: new FormControl("", [Validators.required]),
    accessKey: new FormControl("", [Validators.required]),
    awsRegion: new FormControl(""),
    mfaDevice: new FormControl(""),
    awsProfile: new FormControl("", [Validators.required]),
    azureLocation: new FormControl("", [Validators.required]),
    assumerSession: new FormControl("", [Validators.required]),
    selectAccessStrategy: new FormControl(SessionType.awsIamRoleFederated, [Validators.required]),
  });
Example #12
Source File: location-creation.component.ts    From pantry_party with Apache License 2.0 6 votes vote down vote up
form = this._fb.group ({
    name: ["",
      [ Validators.required ],
      [
        AsyncUniqeName.createValidator(
          this.grocyService.locations().pipe(map(all => all.map(p => p.name)))
        )
      ]
    ],
    description: [""],
    isFreezer: [false]
  });
Example #13
Source File: registration.ts    From ionic-doctor-online with MIT License 6 votes vote down vote up
private buildForm() {

    this.form = this.formBuilder.group({
      password: ['', Validators.compose([Validators.minLength(8), AppValidators.isValidPassword, Validators.maxLength(30), Validators.required])],
      confirm_password: ['', Validators.compose([Validators.minLength(8), AppValidators.isValidPassword, Validators.maxLength(30), Validators.required])],
      username: ['']
    });

  }
Example #14
Source File: browser-outlet.component.ts    From scion-microfrontend-platform with Eclipse Public License 2.0 6 votes vote down vote up
constructor(host: ElementRef<HTMLElement>,
              formBuilder: FormBuilder,
              private _activatedRoute: ActivatedRoute,
              private _overlay: Overlay,
              private _injector: Injector) {
    this.form = formBuilder.group({
      [URL]: new FormControl('', Validators.required),
    });
    this.appEntryPoints = this.readAppEntryPoints();
  }
Example #15
Source File: emote-form.service.ts    From App with MIT License 6 votes vote down vote up
form = new FormGroup({
		name: new FormControl('', [
			Validators.pattern(Constants.Emotes.NAME_REGEXP)
		]),
		tags: new FormControl([]),
		is_private: new FormControl(false),
		is_zerowidth: new FormControl(false),
		emote: new FormControl('')
	});
Example #16
Source File: login-form-ui.component.ts    From svvs with MIT License 6 votes vote down vote up
ngOnInit(): void {
    this.loginForm = new FormGroup({
      login: new FormControl('', [
        Validators.required
      ]),
      password: new FormControl('', [
        Validators.required
      ])
    })
  }
Example #17
Source File: validation.service.ts    From worktez with MIT License 6 votes vote down vote up
async checkTitle(value: String) {
        const control = new FormControl(value, Validators.required);
        if (control.errors === null)
            return (true);
        else {
            let errorType = this.componentName + "_VALIDATION_TITLE";
            this.errorHandlerService.addError(errorType, "Title field is required")
            return (false);
        }
    }
Example #18
Source File: account-page.component.ts    From ReCapProject-Frontend with MIT License 6 votes vote down vote up
createAccountFrom() {
    this.accountForm = this.formBuilder.group({
      firstName: [this.userDetail?.firstName, Validators.required],
      lastName: [this.userDetail?.lastName, Validators.required],
      companyName: [this.userDetail?.companyName, Validators.required],
      nationalIdentity: [''],
      currentPassword: ['', Validators.required],
      newPassword: [''],
    });
  }
Example #19
Source File: login.component.ts    From ngx-admin-dotnet-starter with MIT License 6 votes vote down vote up
ngOnInit(): void {
    const emailValidators = [
      Validators.pattern(EMAIL_PATTERN),
    ];
    this.isEmailRequired && emailValidators.push(Validators.required);

    const passwordValidators = [
      Validators.minLength(this.minLength),
      Validators.maxLength(this.maxLength),
    ];
    this.isPasswordRequired && passwordValidators.push(Validators.required);

    this.loginForm = this.fb.group({
      email: this.fb.control('', [...emailValidators]),
      password: this.fb.control('', [...passwordValidators]),
      rememberMe: this.fb.control(false),
    });
  }
Example #20
Source File: course-dialog.component.ts    From reactive-angular-course with MIT License 6 votes vote down vote up
constructor(
        private fb: FormBuilder,
        private dialogRef: MatDialogRef<CourseDialogComponent>,
        @Inject(MAT_DIALOG_DATA) course:Course,
        private coursesStore: CoursesStore,
        private messagesService: MessagesService) {

        this.course = course;

        this.form = fb.group({
            description: [course.description, Validators.required],
            category: [course.category, Validators.required],
            releasedAt: [moment(), Validators.required],
            longDescription: [course.longDescription,Validators.required]
        });

    }
Example #21
Source File: autocomplete-dialog.ts    From ASW-Form-Builder with MIT License 6 votes vote down vote up
constructor(private formBuilder: FormBuilder,
                public dialogRef: MatDialogRef<AswAutocompleteDialog>,
                @Inject(MAT_DIALOG_DATA) public control: AutoCompleteControl) {
        this.aswEditAutocompleteForm = this.formBuilder.group({
            tooltip: ['', [Validators.required]],
            label: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(25)]],
            name: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(25)]],
            style: ['', [Validators.required]],
            column: [],
            options: this.formBuilder.array([this.createOption()]),
            isRequired: [false]
        });
    }
Example #22
Source File: home.page.ts    From ion-intl-tel-input with MIT License 6 votes vote down vote up
ngOnInit() {
    this.form = new FormGroup({
      phoneNumber: new FormControl({
        value: /* null */this.formValue.phoneNumber,
        disabled: this.disableTest
      }, [
        Validators.required,
        IonIntlTelInputValidators.phone
      ])
    });
  }