How to use the @angular/forms.FormControl 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 spderosso / deja-vu / packages / catalog / market / src / app / market / create-good-name / create-good-name.component.ts View on Github external
{
      provide: NG_VALIDATORS,
      useExisting: CreateGoodNameComponent,
      multi: true
    }
  ]
})
export class CreateGoodNameComponent
    implements OnInit, ControlValueAccessor, Validator {
  @Input() initialValue: string;
  @Output() name: EventEmitter = new EventEmitter();

  // Presentation input
  @Input() inputLabel: string = 'Name';

  nameControl = new FormControl(this.initialValue, [Validators.required]);

  constructor(private elem: ElementRef, private rs: RunService) {}

  ngOnInit() {
    this.nameControl.valueChanges.subscribe((newValue: string) => {
      this.name.emit(newValue);
    });
    this.nameControl.valueChanges.pipe(startWith(this.nameControl.value));
    // set initial value after subscribing to changes so that it will be emitted
    this.nameControl.setValue(this.initialValue);
  }

  writeValue(value: any) {
    if (value) {
      this.nameControl.setValue(value);
    } else {
github rxweb / rxweb / test / reactive-form-validators / validator / pattern.validator.spec.ts View on Github external
() => {
          expect(RxwebValidators.pattern()(new FormControl(null))).toBeNull();
        });
github GetTerminus / terminus-ui / terminus-ui / autocomplete / testing / src / test-components.ts View on Github external
{{ option.foo }}
      
    
  `,
})
export class AutocompleteRequired {
  public myCtrl = new FormControl(null, [Validators.required]);
  public states: State[] = STATES.slice();
}

@Component({
  template: `
    
github Novacer / alpharithmic-trading / frontend / angular-src / src / app / algorithms / regimes-clustering / regimes-clustering.component.ts View on Github external
ngOnInit() {

    this.scroll.scrollTo({
      target: 'top'
    });

    this.firstForm = this.formBuilder.group({firstCtrl: ['', Validators.required]});
    this.secondForm = this.formBuilder.group({secondCtrl: ['', Validators.required]});
    this.thirdForm = this.formBuilder.group({thirdCtrl: ['', Validators.required]});

    const start = new Date();
    start.setFullYear(2016);
    start.setMonth(0);
    start.setDate(1);

    this.startDate = new FormControl(start);

    const end = new Date();
    end.setFullYear(2016);
    end.setMonth(5);
    end.setDate(1);

    this.endDate = new FormControl(end);

    this.capitalBase = 1000000;
    this.ticker = '';

    this.noShorts = false;
    this.useClf = false;

    this.beginSim = false;
    this.validating = false;
github visual-knight / platform-community-edition / apps / visual-knight / src / app / modules / user / components / signup / signup.component.ts View on Github external
ngOnInit() {
    this.signupForm = new FormGroup(
      {
        email: new FormControl('', [Validators.required, Validators.email]),
        password: new FormControl('', [
          Validators.required,
          PasswordStrengthValidators.validatePassword
        ]),
        passwordRepeat: new FormControl('', [Validators.required]),
        privacyPolicy: new FormControl('', (control: FormControl) => {
          const agreed = control.value;
          if (!agreed) {
            return { agreed: true };
          }
          return null;
        }),
        termsAndConditions: new FormControl('', (control: FormControl) => {
          const agreed = control.value;
          if (!agreed) {
            return { agreed: true };
          }
github Sunbird-Ed / SunbirdEd-portal / src / app / client / src / app / modules / workspace / components / update-batch / update-batch.component.ts View on Github external
private initializeUpdateForm(): void {
    const endDate = this.batchDetails.endDate ? new Date(this.batchDetails.endDate) : null;
    this.batchUpdateForm = new FormGroup({
      name: new FormControl(this.batchDetails.name, [Validators.required]),
      description: new FormControl(this.batchDetails.description),
      enrollmentType: new FormControl(this.batchDetails.enrollmentType, [Validators.required]),
      startDate: new FormControl(new Date(this.batchDetails.startDate), [Validators.required]),
      endDate: new FormControl(endDate),
      mentors: new FormControl(),
      users: new FormControl()
    });
    this.batchUpdateForm.valueChanges.subscribe(val => {
      if (this.batchUpdateForm.status === 'VALID') {
        this.disableSubmitBtn = false;
      } else {
        this.disableSubmitBtn = true;
      }
    });
  }
  /**
github GNS3 / gns3-web-ui / src / app / components / project-map / node-editors / configurator / switch / configurator-switch.component.ts View on Github external
constructor(
        public dialogRef: MatDialogRef,
        public nodeService: NodeService,
        private toasterService: ToasterService,
        private formBuilder: FormBuilder
    ) {
        this.nameForm = this.formBuilder.group({
            name: new FormControl('', Validators.required),
        });

        this.inputForm = this.formBuilder.group({
            sourcePort: new FormControl('', Validators.required),
            sourceDlci: new FormControl('', Validators.required),
            destinationPort: new FormControl('', Validators.required),
            destinationDlci: new FormControl('', Validators.required),
        });
    }
github mregni / EmbyStat / EmbyStat.Web / ClientApp / src / app / pages / wizard / wizard-overview / wizard-overview.component.ts View on Github external
@Component({
  selector: 'es-wizard',
  templateUrl: './wizard-overview.component.html',
  styleUrls: ['./wizard-overview.component.scss']
})

export class WizardOverviewComponent implements OnInit, OnDestroy {
  @ViewChild('stepper') private stepper: MatStepper;

  administratorsSub: Subscription;
  administrators: MediaServerUser[];

  introFormGroup: FormGroup;
  nameControl = new FormControl('', [Validators.required]);
  languageControl = new FormControl('en-US', [Validators.required]);

  serverForm: FormGroup;
  serverAddressControl = new FormControl('', [Validators.required]);
  serverPortControl = new FormControl('', [Validators.required]);
  serverProtocolControl = new FormControl('1', [Validators.required]);
  serverApiKeyControl = new FormControl('', [Validators.required]);
  selectedAdministratorControl = new FormControl('');


  exceptionLoggingControl = new FormControl(false);

  private languageChangedSub: Subscription;
  private searchEmbySub: Subscription;
  private settingsSub: Subscription;
  private fireSyncSub: Subscription;
  private serverPortControlChange: Subscription;
github ng-vcl / ng-vcl / demo / app / demos / form-control-group / demo.component.ts View on Github external
Validators.email,
    ]),
    terms: new FormControl(false, [
      (control) => {
        if (!control.value) {
          return {
            termsDisagree: true,
          };
        }
        return null;
      }
    ]),
    gender: new FormControl(null, Validators.required),
    class: new FormControl(null, [ Validators.required ]),
    alignment: new FormControl(null, [ Validators.required ]),
    hitpoints: new FormControl(this.defaultValues.hitpoints, [ Validators.min(1), Validators.max(100)]),
    strength: new FormControl(this.defaultValues.strength, [ Validators.min(1), Validators.max(10)]),
    agility: new FormControl(this.defaultValues.agility, [ Validators.min(1), Validators.max(10)]),
    intelligence: new FormControl(this.defaultValues.intelligence, [ Validators.min(1), Validators.max(10)]),
    perks: new FormControl(this.defaultValues.perks, [ this.validatePerks.bind(this) ])
  }, [
    this.validateSkills.bind(this)
  ]);

  get level() {
    const c = this.formGroup && this.formGroup.get('level');
    return c ? c.value : 0;
  }

  get skillPoints() {
    const s = this.formGroup && this.formGroup.get('strength');
    const a = this.formGroup && this.formGroup.get('agility');