Questions tagged angular-custom-validators

Explore the latest questions and answers asked by our top developers.

Angular 11 Custom ISBN Validator Reactive Forms

I’m doing a custom validation for an ISBN number, I already have the function that checks the number and works perfect giving me the response by console, but I need to do the custom validator to get the error in the view with the form control and in this step this error is showing in […]

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’, [Validators.required, Validators.maxLength(3)], ValidateUserNotTaken.createValidator(this.signupService) ], email: [ ”, [Validators.required, Validators.email], ValidateEmailNotTaken.createValidator(this.signupService) ] }); // watch for status Changes this.signupForm.statusChanges.subscribe(status => { […]

Async validator for unique userId not working

Inside service- getUserIdToCheckDuplicate(userId:any):Observable<any>{ const url = “; //url goes here return this.http.get<any>(url); } Inside component- ngOnInit(): void { this.form = this.fb.group({ userId: [”, [Validators.required],[this.existingUserIdValidator()]] } get userId() { return this.form.get("userId"); } existingUserIdValidator(initialID: string = ""): AsyncValidatorFn { return ( control: AbstractControl ): | Promise<{ [key: string]: any } | null> | Observable<{ [key: string]: any […]

Angular custom component show invalid form elements on submit

I have an reactive angular form which containing several custom form component. I have created this components to use in several forms and I have inherited from "ControlValueAccessor" interface, it is working good , I see the values of each custom components and see if the form and components are valid or not. But I […]

Display cross field custom validation error message

In my reactive form i have built a custom validation for 3 input fields. The main function of the validation is to return a error when either 1/2 out of 3 input fields have a value (I want all 3 fields to be required as soon as the user enters a value in 1 field). […]

Angular (12.0.5) Formbuilder regex validation

I am trying to validate passwords, postal codes and phone numbers using the Angular pattern validators. For some reason the password and postal code validation just don’t seem to work, no matter which regex I try. The phone number regex works just fine though, which confuses me even more. I’m not sure where the error […]

Run control Validators on different value than the ngModel’s one

Long stroy short, i’m currently working on a directive that applies a function to a control value when modified. That function modifies the control value only in on the model side. That goes like this : // import … // @Directive export class ControlValuePipeDirective implements OnInit{ @Input() ngxControlValuePipe?: (value? :any) => any; constructor( private ngControl: […]

In Angular can custom validators be used in material dialog template

I just want to check I’m not going down a blind alley. I have a data entry form in a Material Dialog as a Template form. I want to apply some custom validators to some of its Input fields. I’m not having any success making them fire (although I tested one and it works on […]

In Angular how can custom validators be used in material dialog template

I have a data entry form in a Material Dialog as a Template form. I want to apply some custom validators to some of its Input fields. I’m not having any success making them fire (although I tested one and it works on another "normal" form). Is there an issue trying to use them in […]

Pass a dynamic parameter in reactive form custom validator

I would like to pass a variable as a parameter in a custom validator like this newSimulation: new FormControl(”, [uniqNameValidator(this.options)]) Then use it in my custom validator export function uniqNameValidator(list: any): ValidatorFn { return (control: AbstractControl): ValidationErrors | null => { const simulationFlatList = list.map(val => val.closingPeriodSimulationName) return simulationFlatList.indexOf(control.value) > -1 ? { message: "simulation […]

1 3

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq