Angular 5 solely validation on blur?

前端 未结 3 1224
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 17:37

I wonder if it is possible to have the validation in reactive forms on blur. At the moment you can set updateOn: \"blur\" but then the values of the input fields wo

3条回答
  •  隐瞒了意图╮
    2021-02-15 18:05

    What I eventually have done:

    Using reactive forms:

    TS

    this is the form to make. I needed the productCost and loanAmount to be validated on blur but the values itself needed to update onchange. If you set updateOn: "blur" the validation happens after the blur event but als the values will update after the blur event.

    let formToMake = {
          productCost: new FormControl(null, {validators: Validators.required, updateOn: "blur"}),
          loanAmount: new FormControl(null, {validators: Validators.compose([Validators.required, Validators.min(2500)]), updateOn: "blur"}),
          loanLength: new FormControl(49, {validators: Validators.required, updateOn: "change"})
        };
    

    handleInput method:

    To solve this I just made an event handler which will be called on the input event.

    TS

    handleInput(e: any) {
        this.loanAmount = e;
      }
    

    HTML

    
    

提交回复
热议问题