在以角度反应形式将其传递到自定义验证之前,如何更改或修改输入文本字符串值

时间:2019-02-08 05:30:10

标签: javascript angular customvalidator

这是我用于表单初始化的代码,我希望每次将读取值转换为数字后再通过验证

this.meterForm = this.formBuilder.group({
      'reading': [newReading, this.getValidator(this.meter)],
      'date': [this.date],
      'time': [this.time],
      'comments': [comments]
    });
    
      public getValidator(aMeter: Meter): ValidatorFn {
    if (this.meter.type === this.generalInfo.meterTypes.counter) {
    // I want to change the 'reading' input text field which is a string to number 
      return Validators.compose([
        Validators.required,
        WorkorderValidators.maxLength(18),
        WorkorderValidators.max(this.meter.maxValue),
        WorkorderValidators.min(this.meter.minValue),
        WorkorderValidators.increment(0.0001, this.meter.minValue),
        WorkorderValidators.precision(3)
      ]);
    } else {
      return Validators.compose([
        Validators.required,
        this.meterReadingValueValidation(18, 3)
      ]);
    }
  }

0 个答案:

没有答案