mrchandoo / cordova-plugin-decimal-keyboard

Cordova plugin to show decimal keyboard on iPhones
Apache License 2.0
37 stars 71 forks source link

validation issue (requiredPattern) #15

Open rhanesoghlyan opened 6 years ago

rhanesoghlyan commented 6 years ago

Due to this pattern (pattern="[0-9]*") my form-control is invalid when typing decimal number. When using other pattern plugin doesn't work

aycron-dev commented 6 years ago

I'm having the same problem

mrchandoo commented 5 years ago

you need to take out the form control from your auto validations by angular etc and do your own validation based on the form control value.

rhanesoghlyan commented 5 years ago

There is HTML validation for input field. pattern="[0-9]*"

Artux-White commented 4 years ago

Found a workaround. Leave the pattern as it is (pattern="[0-9]*") in the input element and then clear and then set the needed validators on input focus.

    this.myForm.controls["hours"].setValidators(null);
    this.myForm.controls["hours"].setValidators(
      Validators.pattern(/^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/)
    );
    Object.keys(this.myForm.controls).forEach(key => {
      this.myForm.controls[key].markAsDirty();
    });
    this.myForm.updateValueAndValidity();