@angular/forms#FormControl TypeScript Examples

The following examples show how to use @angular/forms#FormControl. 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: app.component.ts    From gnosis.1inch.exchange with MIT License 7 votes vote down vote up
private getFilteredTokens(form: FormControl): Observable<ITokenDescriptor[]> {

        return combineLatest([
            this.sortedTokens$,
            form.valueChanges.pipe(
                startWith('')
            ),
        ]).pipe(
            map((x) => {
                const [tokens, filterText] = x;
                return filterTokens(tokens, filterText);
            })
        );
    }
Example #2
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 #3
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 #4
Source File: confirm-trezor-keys.component.ts    From xBull-Wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
async requestAccounts(): Promise<void> {
    const amountOfAccountsLoaded = this.accounts.length;
    let response: Unsuccessful | Success<StellarAddress[]>;
    try {
      response = await this.hardwareWalletsService.getTrezorPublicKeys({
        start: amountOfAccountsLoaded,
        end: amountOfAccountsLoaded + 4,
      });
    } catch (e: any) {
      console.error(e);
      this.nzMessageService.error(`There was an error we didn't expect, try again or contact support`, {
        nzDuration: 5000
      });
      return;
    }

    if (!response.success) {
      this.nzMessageService.error(`We can't continue`, {
        nzDuration: 5000,
      });
      return;
    }

    response.payload.forEach(record => {
      this.accounts.push(new FormGroup({
        publicKey: new FormControl(record.address),
        path: new FormControl(record.serializedPath),
        active: new FormControl(true),
      }));
    });
  }
Example #5
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 #6
Source File: command-bar.component.ts    From leapp with Mozilla Public License 2.0 6 votes vote down vote up
filterForm = new FormGroup({
    searchFilter: new FormControl(""),
    dateFilter: new FormControl(true),
    providerFilter: new FormControl([]),
    profileFilter: new FormControl([]),
    regionFilter: new FormControl([]),
    integrationFilter: new FormControl([]),
    typeFilter: new FormControl([]),
  });
Example #7
Source File: home.component.ts    From Angular-Cookbook with MIT License 6 votes vote down vote up
ngOnInit() {
    this.componentAlive = true;
    this.searchForm = new FormGroup({
      username: new FormControl('', []),
    });
    this.searchUsers();
    this.searchForm
      .get('username')
      .valueChanges.pipe(
        takeWhile(() => !!this.componentAlive),
        debounceTime(300)
      )
      .subscribe(() => {
        this.searchUsers();
      });
  }
Example #8
Source File: async-unique-name.ts    From pantry_party with Apache License 2.0 6 votes vote down vote up
static createValidator(
    existingNames: Observable<string[]>,
    errorStr: string = "valueExists"
  ): AsyncValidator {
    return {
      validate: (control: FormControl) => {
        const value = control.value.toLowerCase();

        return existingNames.pipe(
          map(names => !!names.find(n => n.toLowerCase() === value)),
          map(found => found ? {[errorStr]: true} : null)
        );
      }
    };
  }
Example #9
Source File: AppValidators.ts    From ionic-doctor-online with MIT License 6 votes vote down vote up
static optionalEmailIfBlank(control: FormControl): any {
    // skip validation if empty (Validators.required should handle this)
    if (!control.value) {
      return null;
    }
    let exp = new RegExp(`^${AppValidators.EMAIL_REGEX}$`);
    if (exp.test(control.value)) {
      return null;
    }
    return {isValid: true};
  }
Example #10
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 #11
Source File: emote-create.component.ts    From App with MIT License 6 votes vote down vote up
uploadEmoteFile(file: File | null): void {
		if (!(file instanceof File)) return this.loggerService.debug(`Canceled emote upload`), undefined;
		const reader = new FileReader();
		const control = this.form.get('emote') as FormControl;

		if (file.size > 5000000) {
			this.emoteFormService.uploadError.next('File must be under 5.0MB');
			control.setErrors({ image_size_too_large: true });

			return undefined;
		} else {
			this.emoteFormService.uploadError.next('');
			control.setErrors({ image_size_too_large: false });
		}

		reader.onload = (e: ProgressEvent) => {
			this.emoteFormService.uploadedEmote.next(String((e.target as { result?: string; }).result));

			if (control) {
				control.patchValue(file);
				control.setErrors(null);
				control.markAsDirty();
			}

			return undefined;
		};

		reader.readAsDataURL(file);
		return undefined;
	}
Example #12
Source File: get-bg-class.pipe.ts    From colo-calc with Do What The F*ck You Want To Public License 6 votes vote down vote up
public transform(control: FormControl): Observable<ReturnType> {
    return control.valueChanges.pipe(
      startWith(control.value),
      map((value: ClassKey) => {
        const code: ClassKey = (value as ClassKey)|| Background.Solid;
        console.log(code, valueToClassName[code]);
        return { [valueToClassName[code]]: true };
      })
    )
  }
Example #13
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 #14
Source File: home.component.ts    From one-platform with MIT License 5 votes vote down vote up
whitespaceValidator(control: FormControl) {
    const isWhitespace = (control.value || '').trim().length === 0;
    const isValid = !isWhitespace;
    return isValid ? null : { whitespace: true };
  }
Example #15
Source File: option-selector.component.ts    From 1x.ag with MIT License 5 votes vote down vote up
optionSearchControl = new FormControl('');
Example #16
Source File: app.component.ts    From gnosis.1inch.exchange with MIT License 5 votes vote down vote up
swapForm = new FormGroup({
        fromAmount: new FormControl('', this.tokenAmountInputValidator),
        toAmount: new FormControl('', [...this.tokenAmountInputValidator]),
    });
Example #17
Source File: generic-form.component.ts    From Smersh with MIT License 5 votes vote down vote up
public period = new FormGroup({
    start: new FormControl(),
    stop: new FormControl(),
  });
Example #18
Source File: layout-v1-account-horizon-selector.component.ts    From xBull-Wallet with GNU Affero General Public License v3.0 5 votes vote down vote up
horizonSelectControl: FormControl = new FormControl('', [Validators.required]);
Example #19
Source File: deposit-form.component.ts    From rubic-app with GNU General Public License v3.0 5 votes vote down vote up
public readonly brbcAmountCtrl = new FormControl(null);