Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation issue (requiredPattern) #15

Open
rhanesoghlyan opened this issue Feb 22, 2018 · 4 comments
Open

validation issue (requiredPattern) #15

rhanesoghlyan opened this issue Feb 22, 2018 · 4 comments

Comments

@rhanesoghlyan
Copy link

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
Copy link

I'm having the same problem

@mrchandoo
Copy link
Owner

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
Copy link
Author

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

@Artux-White
Copy link

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants