How to use the @angular/forms.Validators.max 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 intershop / intershop-pwa / src / app / shared / forms / components / input-birthday / input-birthday.component.ts View on Github external
private createForm() {
    this.dateForm = this.fb.group({
      day: ['', [Validators.min(this.minDay), Validators.max(this.maxDay)]],
      month: ['', [Validators.min(this.minMonth), Validators.max(this.maxMonth)]],
      year: ['', [Validators.min(this.minYear), Validators.max(this.maxYear)]],
    });

    /* Add form group temporarily to the parent form to prevent a form submit with an invalid birth date
    FM: commented out because child components don't change parent components' stuff
    this.form.addControl('birthday-form', this.dateForm); */
  }
github Squidex / squidex / frontend / app / framework / angular / forms / error-formatting.spec.ts View on Github external
it('should format max', () => {
        const error = validate(3, Validators.max(2));

        expect(error).toEqual('MY_FIELD must be less or equal to \'2\'.');
    });
github thingsboard / thingsboard / ui-ngx / src / app / modules / home / pages / device / device-credentials-dialog.component.ts View on Github external
updateValidators(): void {
    const crendetialsType = this.deviceCredentialsFormGroup.get('credentialsType').value as DeviceCredentialsType;
    switch (crendetialsType) {
      case DeviceCredentialsType.ACCESS_TOKEN:
        this.deviceCredentialsFormGroup.get('credentialsId').setValidators([Validators.max(20), Validators.pattern(/^.{1,20}$/)]);
        this.deviceCredentialsFormGroup.get('credentialsId').updateValueAndValidity();
        this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([]);
        this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity();
        break;
      case DeviceCredentialsType.X509_CERTIFICATE:
        this.deviceCredentialsFormGroup.get('credentialsValue').setValidators([Validators.required]);
        this.deviceCredentialsFormGroup.get('credentialsValue').updateValueAndValidity();
        this.deviceCredentialsFormGroup.get('credentialsId').setValidators([]);
        this.deviceCredentialsFormGroup.get('credentialsId').updateValueAndValidity();
        break;
    }
  }
github Farata / angulartypescript / code-samples / Angular5 / chapter11 / ng-auction / src / app / shared / components / search-form / search-form.component.ts View on Github external
constructor(fb: FormBuilder, private router: Router) {
    this.searchForm = fb.group({
      title   : [, Validators.minLength(2)],
      minPrice: [, Validators.min(0)],
      maxPrice: [, [Validators.min(0), Validators.max(10000)]]
    }, {
      validator: [ minLessThanMaxValidator ]
    });
  }
github atinc / ngx-tethys / src / form / validator / max-validator.directive.ts View on Github external
@Input() public set max(value: string) {
        this._validator = Validators.max(parseFloat(value));
    }
github swimlane / ngx-ui / projects / swimlane / ngx-ui / src / lib / components / input / input.component.ts View on Github external
validate(c: FormControl) {
    if (this.type !== 'number') {
      return null;
    }
    return {
      ...Validators.max(this.max)(c),
      ...Validators.min(this.min)(c)
    };
  }
github betagouv / preuve-covoiturage / dashboard / src / app / modules / campaign / components / campaign-form / step-3 / staggered-form / staggered-form.component.ts View on Github external
initForm() {
    this.controls.min.setValidators(Validators.required);
    this.controls.max.setValidators(Validators.required);
    this.controls.max.enable();
    if (this.isFirst) {
      const min = this.globalMinDistance;
      this.minValue = min;
      const max = this.globalMaxDistance;
      this.controls.max.setValidators([Validators.required, Validators.min(min + 1), Validators.max(max)]);
      this.controls.min.setValue(min);
    }
    if (this.isLast) {
      this.controls.max.disable();
    }
  }
github swimlane / ngx-ui / src / components / input / input.component.ts View on Github external
public validate(c: FormControl) {
    if (this.type !== 'number') {
      return null;
    }
    return {
      ...Validators.max(this.max)(c),
      ...Validators.min(this.min)(c)
    };
  }
github intershop / intershop-pwa / src / app / shared / product / components / product-quantity / product-quantity.component.ts View on Github external
getValidations(): ValidatorFn {
    if (this.type !== 'select') {
      return Validators.compose([
        Validators.required,
        Validators.min(this.allowZeroQuantity ? 0 : this.product.minOrderQuantity),
        Validators.max(this.product.maxOrderQuantity),
        SpecialValidators.integer,
      ]);
    }
  }