How to use the @angular/forms.Validators.min 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 Teradata / covalent / src / platform / dynamic-forms / services / dynamic-forms.service.ts View on Github external
createValidators(config: ITdDynamicElementConfig): ValidatorFn {
    let validator: ValidatorFn;
    if (config.required) {
      validator = Validators.required;
    }
    if (config.max || config.max === 0) {
      validator = Validators.compose([validator, Validators.max(parseFloat(config.max))]);
    }
    if (config.min || config.min === 0) {
      validator = Validators.compose([validator, Validators.min(parseFloat(config.min))]);
    }
    if (config.maxLength || config.maxLength === 0) {
      validator = Validators.compose([validator, Validators.maxLength(parseFloat(config.maxLength))]);
    }
    if (config.minLength || config.minLength === 0) {
      validator = Validators.compose([validator, Validators.minLength(parseFloat(config.minLength))]);
    }
    // Add provided custom validators to the validator function
    if (config.validators) {
      config.validators.forEach((validatorConfig: ITdDynamicElementValidator) => {
        validator = Validators.compose([validator, validatorConfig.validator]);
      });
    }
    return validator;
  }
}
github mprove-io / mprove / src / app / components / chart-controls-input / chart-control-angle-span / chart-control-angle-span.component.ts View on Github external
buildAngleSpanForm() {
    this.angleSpanForm = this.fb.group({
      angleSpan: [
        this.chart.angle_span,
        Validators.compose([
          Validators.required,
          services.ValidationService.integerValidator,
          Validators.min(0)
        ])
      ]
    });

    this.angleSpan = this.angleSpanForm.controls['angleSpan'];

    this.angleSpanChange.emit({
      angleSpanValid: this.angleSpanForm.valid
    });
  }
github songyaofeng / angular6-admin / src / app / routes / user / edit / edit.component.ts View on Github external
formInit() {
        this.form = this.fb.group({
            username: ['', [Validators.required]],
            realname: ['', [Validators.required]],
            mobile: ['', [Validators.required]],
            profile: ['', [Validators.required]],
            avatar: ['', [Validators.required]],
            id: ['', [Validators.required]],
            status: ['', [Validators.min(1), Validators.max(2)]],
        });
    }
github Ninja-Squad / globe42 / frontend / src / app / person-per-unit-revenue-information-edit / person-per-unit-revenue-information-edit.component.ts View on Github external
constructor(private route: ActivatedRoute,
              private perUnitRevenueInformationService: PerUnitRevenueInformationService,
              private router: Router,
              fb: FormBuilder) {
    this.infoGroup = fb.group({
      adultLikeCount: [1, [Validators.required, Validators.min(1)]],
      childCount: [0, [Validators.required, Validators.min(0)]],
      monoParental: [false],
    });
  }
github Azure / BatchExplorer / src / app / components / gallery / submit / parameter-input / parameter-input.component.ts View on Github external
private _updateValidators() {
        const validatorGroup: any[] = [];
        const parameterTemplate = this.parameter.param;
        if (parameterTemplate.type === NcjParameterRawType.int) {
            if (parameterTemplate.minValue) {
                validatorGroup.push(Validators.min(parameterTemplate.minValue));
            }
            if (parameterTemplate.maxValue) {
                validatorGroup.push(Validators.max(parameterTemplate.maxValue));
            }
        }

        if (parameterTemplate.type === NcjParameterRawType.string) {
            if (parameterTemplate.minLength) {
                validatorGroup.push(Validators.minLength(parameterTemplate.minLength));
            }
            if (parameterTemplate.maxLength) {
                validatorGroup.push(Validators.maxLength(parameterTemplate.maxLength));
            }
        }

        this.parameterValue.setValidators(Validators.compose(validatorGroup));
github inspursoft / board / src / ui / src / app / shared / cs-components-library / cs-input / cs-input.component.ts View on Github external
this.inputValidatorFns.push(Validators.pattern(InputPatternNumber));
    }
    if (this.inputIsRequired) {
      this.inputValidatorFns.push(Validators.required);
    }
    if (this.inputMaxlength > 0) {
      this.inputValidatorFns.push(Validators.maxLength(this.inputMaxlength));
    }
    if (this.inputMinlength > 0) {
      this.inputValidatorFns.push(Validators.minLength(this.inputMinlength));
    }
    if (this.inputMax > 0) {
      this.inputValidatorFns.push(Validators.max(this.inputMax));
    }
    if (this.inputMin > 0) {
      this.inputValidatorFns.push(Validators.min(this.inputMin));
    }
    if (this.inputPattern) {
      this.inputValidatorFns.push(Validators.pattern(this.inputPattern));
    }
    if (this.customerValidatorFns) {
      this.customerValidatorFns.forEach(value => {
        this.inputValidatorFns.push(value);
      })
    }
  }
github ffxiv-teamcraft / ffxiv-teamcraft / apps / client / src / app / pages / gc-supply / gc-supply / gc-supply.component.ts View on Github external
const groupConfig = sets.reduce((group, set) => {
          group[set.jobId] = [set.level, [Validators.required, Validators.min(1)]];
          return group;
        }, {});
        return fb.group(groupConfig);
github mprove-io / mprove / src / app / components / project / update-query-size-limit / update-query-size-limit.component.ts View on Github external
buildForm(): void {
    this.updateQuerySizeLimitForm = this.fb.group({
      querySizeLimit: [
        this.querySizeLimit,
        Validators.compose([
          Validators.required,
          Validators.min(0),
          Validators.maxLength(255)
        ])
      ]
    });
  }
github ceph / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / pool / pool-form / pool-form.component.ts View on Github external
private setCompressionValidators() {
    CdValidators.validateIf(this.form.get('minBlobSize'), () => this.hasCompressionEnabled(), [
      Validators.min(0),
      CdValidators.custom('maximum', (size) =>
        this.oddBlobSize(size, this.form.getValue('maxBlobSize'))
      )
    ]);
    CdValidators.validateIf(this.form.get('maxBlobSize'), () => this.hasCompressionEnabled(), [
      Validators.min(0),
      CdValidators.custom('minimum', (size) =>
        this.oddBlobSize(this.form.getValue('minBlobSize'), size)
      )
    ]);
    CdValidators.validateIf(this.form.get('ratio'), () => this.hasCompressionEnabled(), [
      Validators.min(0),
      Validators.max(1)
    ]);
  }