Questions tagged [angular-custom-validators]

Question regarding building the custom validator function for Angular Reactive Form. Please also apply tags: [angular], [angular-reactive-forms].

Resources:

74 questions
5
votes
2 answers

Angular: Trigger a form control validation on change of another form control

Please refer the project in a stackblitz here. As can be seen, I have reactive form with controls as firstNumber, secondNumber and thirdNumber. I need to have validation for form control thirdNumber such that its value should not be greater than the…
4
votes
2 answers

Reactive forms angular show error for pattern in angular

I have reactive form like this this.form = this.formBuilder.group({ email: ['', [ Validators.required, Validators.maxLength(120), Validators.pattern('^[^\\s@]+@[^\\s@]+\\.[^\\s@]{1,}$') ]], }); Now I need to…
4
votes
1 answer

Form stuck in PENDING status with async validator when value changed on construction

When using reactive forms with an async validator on the form group, and if changing the values of the form group by using patchValue in the constructor or in ngOnInit - even though the async validator observable completes, the form remains in…
Aviad P.
  • 32,036
  • 14
  • 103
  • 124
3
votes
1 answer

Angular Unit Test for Custom Validator FormGroup

How to unit test (Jest here) custom validator, which has FormGroup? I've seen this question, but it's about FormControl. The function to be tested. import { FormGroup } from '@angular/forms'; /** * @description Validate if passwords are…
3
votes
1 answer

setValidators doesn't work at all when set dynamically inside of a function

I am not sure why setValidators is not working in my below code. I am not sure what the issue is as it doesn't take any effect when I set the formControl as required. What I want to achieve is to dynamically set some FormControls required if a…
3
votes
1 answer

Regex expression with Validators.pattern for just integer number

I am trying to create a validator for only integers (e.g., 60) using Regex. Here how I am trying to do it: meter: ["", Validators.required, Validators.pattern(/[0-9]/)] It does not work, but I have to say I am not familiar with this technique.…
3
votes
2 answers

Angular Forms: How to avoid multiple NgIf divs for validation error messages?

I would like to simplify the code below:
Date can't be in the future.
Harry
  • 546
  • 6
  • 22
  • 50
2
votes
4 answers

Angular custom validator not firing when input untouched?

I have a reactive form as following: this.form = this.formBuilder.group({ name: ['', Validators.required], email: ['', this.customValidator()] }); I also have a "submit" button with a [disabled] condition:
2
votes
1 answer

Wait for async validators to finish angular forms

I have an angular form with custom aync validators I want to do some stuff if the form is invalid on load. Here is the code ngOnInit() { this.signupForm = this.fb.group({ name: [ 'Prasad P', …
2
votes
1 answer

Custom validator with parameter is not working for textbox and checkbox in angular

In my reactive form, I have a textbox and a checkbox. I want that when the checkbox is checked, then textbox can be null or empty. If checkbox is not checked then validation message should be shown for required value. So I have written a custom…
2
votes
0 answers

ionic angular strange issue- custom form validator not getting called on android

I am working on ionic 4 angular mobile app. I am facing one strange issue wherein custom form validation is not getting called on android device but its getting called and working as per expectation. After going into detail it seems that if the…
2
votes
3 answers

Angular Custom Async Validator Not Showing Error

My async validator is not working when I actually make an async call (but works when I mock it with Observable.of(result). The html looks like this:
VSO
  • 11,546
  • 25
  • 99
  • 187
2
votes
1 answer

Password and Confirm Password match validation in ionic4 form

I have created a signup form in ionic4 with fields like first name, last name, email, password and confirm password. I have added validations also like showing the fields are required if user left or touch the respective fields. I wanted to add…
2
votes
1 answer

Accessing formgroup in custom validator

I'm trying to add custom validator to my component.ts customvalidatorFile: import { FormGroup, ValidationErrors } from '@angular/forms'; export class ProfileCustomValidators { static validateTime(fg: FormGroup): ValidationErrors { …
2
votes
2 answers

Get sibling AbstractControl from Angular reactive FormArray - Custom Validation

I'm having a Contact form in Angular using a Reactive form. The form contains firstName, lastName and an Array of address. Each address formgroup contains a checkbox, if the checkbox is checked, validation of the State text box mandatory is needed,…
1
2 3 4 5