Unfortunately, I am unable to utilize my Async Validator as it is wrapped within the "__zone_symbol" object

I have created an asynchronous validator for passwords.

export class PasswordsValidators{
    static oldPasswordMatch(control: AbstractControl) : Promise<ValidationErrors> | null {
        return new Promise((resolve) => {
            if(control.value !== "1234")
                resolve({oldPasswordInvalid:true})
            else
                resolve(null); 
        });
    }
}

However, I am unable to access the oldPasswordInvalid variable as it is enclosed within an object named __zone_symbol__value.

https://i.sstatic.net/aHyuc.png

This is the formGroup setup:

  form = new FormGroup({
    oldPassword: new FormControl("",[
      Validators.required,
      PasswordsValidators.oldPasswordMatch
    ]),
    newPassword: new FormControl("",[
      Validators.required      
    ]),
    confirmPassword: new FormControl("",[
      Validators.required      
    ])
  })

This is how the front-end is structured:

  <div class="form-group">
    <label>Old Password</label>
    <input 
    formControlName="oldPassword"
    type="password" 
    class="form-control" 
    placeholder="Password">
    <div class="alert alert-danger" *ngIf="oldPassword.invalid && oldPassword.touched">
      <p *ngIf="oldPassword.errors.required"> Should be filled </p>
      <p *ngIf="oldPassword.errors.oldPasswordInvalid">Didn't match</p>
    </div>
  </div>

I would appreciate any insights on what could be missing in my implementation.

Answer №1

The issue arises when you mix async validators with synchronous ones in your form setup. Here's a better approach:

form = new FormGroup({
    oldPassword: new FormControl("",
      [Validators.required],
      [PasswordsValidators.oldPasswordMatch] // Ensure that async validators are the third parameter
    ),
    newPassword: new FormControl("",[
      Validators.required      
    ]),
    confirmPassword: new FormControl("",[
      Validators.required      
    ])
  })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to utilize the .keyCode method within a query selector

Trying to utilize .keyCode in JavaScript to identify a pressed key, but the console consistently displays null after each key press. Below is the relevant CSS code: <audio data-key="65" src="sounds\crash.mp3"></audio> ...

Creating folders and writing data to text files in Angular 4/5 with TypeScript: A tutorial

Is it feasible to create a folder, text file, and write data into that file in Angular5 using Typescript for the purpose of logging errors? Your expertise on this matter would be greatly appreciated. Thank you in advance! ...

When the form is submitted, the text input vanishes and then the page is refreshed using AJAX technology

Can anyone help me troubleshoot why my page is reloading even though I used AJAX, and how to prevent it from clearing my input text after clicking the submit button? I tried using the show method to resolve this issue but it didn't work. <form met ...

Error message: The function for the AJAX call is not defined

I'm currently working with jQuery's ajax function and encountering an error: 'getQty is not defined' Can you spot my mistake here? jQuery Code: function getQty() { var dataString = "itemId=" +$(".itemId").val(); $.ajax({ t ...

Steps to Deploying a Typescript Express Application on Azure App Services

As I work on deploying a Typescript express app in Azure app services, I encountered an error message when trying to access my app's URL: You do not have permission to view this directory or page. I followed the same deployment process that I typica ...

Beginner coding exercises to master JavaScript

With a proficiency in CSS, HTML, and some knowledge of Jquery and PHP, I aspire to become a Front End Web Developer. However, my lack of understanding in Javascript is holding me back. I acquired my current skillset by rapidly learning over 9 months while ...

Modifying a CSS property with jQuery

If I have the following HTML, how can I dynamically adjust the width of all "thinger" divs? ... <div class="thinger">...</div> <div class="thinger">...</div> <div class="thinger">...</div> ... One way to do this is usi ...

I must create a dropdown and lift up feature similar to the one provided in the example

I am looking to implement a drop-down navigation bar on the top right and a pop-up button/links on the top left. The drop-down menu should appear when the screen size reaches a certain pixel width. If you can't see the drop-down navigation (NAV), adju ...

What is the best way to implement data validation for various input fields using JavaScript with a single function?

Users can input 5 numbers into a form, each with the same ID but a different name. I want to validate each input and change the background color based on the number entered - red for 0-5, green for 6-10. I wrote code to change the color for one input box, ...

Guidelines for assigning dynamic values from an array to a button in Angular2

I am a beginner in Angular and I am looking to display dynamic data with edit and delete buttons. I have managed to display the data properly with headers and everything, but now I want to add an edit button. Currently, I am passing each record's ID ...

When attempting to use focusin/focusout, I encountered the following error: Uncaught TypeError - The property 'addEventListener' cannot be read from null

When attempting to utilize the DOM events focusin/focusout, I encountered an error: Uncaught TypeError: Cannot read property 'addEventListener' of null. The issue seems to be originating from main.js at lines 18 and 40. I am using Chrome as my b ...

Send the form with validation in place

Currently, I am in the process of developing a code to handle form submissions using React alongside Typescript and Material-UI: export default function OpenTicket(props: any) { const classes = useStyles(); const formHandler = (e: React.FormEvent& ...

Issue: unable to inject ngAnimate due to uncaught object error

Whenever I attempt to inject 'ngAnimate' into my app, I encounter issues with instantiation. Here is the code snippet in question: var app = angular.module('musicsa', [ 'ngCookies', 'ngResource', 'ngSanit ...

Unable to break down the property 'desks' of '(0 , _react.useContext)(...)' due to its undefined nature

Trying to mock DeskContext to include desks and checkIfUserPresent when calling useContext is causing an error to occur: Cannot destructure property 'desks' of '(0 , _react.useContext)(...)' as it is undefined TypeError: Cannot destruct ...

Netlify failing to build CRA due to inability to locate local module for method?

I encountered an issue with deploying my site on Netlify. The problem arises when it fails to locate local modules. Below is the log: 12:54:43 AM: Build ready to start 12:54:45 AM: build-image version: 09c2cdcdf242cf2f57c9ee0fcad9d298fad9ad41 12:54:45 AM: ...

Struggling with configuring AngularJS?

I've been working on a simple setup, but I can't figure out why AngularJS isn't displaying the content within the curly brackets. It's got me completely baffled. If you'd like to check it out, here's the link to the plunker: ...

Would it be appropriate to use require("fs") instead of require("node:fs") as a workaround in the OpenAI package?

I have inherited a project and am currently integrating OpenAI into it. Initially, I was informed to use Node 16, but after consulting with other developers on the project, I discovered that everyone is actually using version 14.17.3. The OpenAI package c ...

Steps to activate a single button within a deactivated fieldset

Is there a way to deactivate all elements within a Fieldset, while keeping certain buttons active? Check out this demo. <fieldset ng-disabled="true"> <legend>Personalia:</legend> Name: <input type="text"><br> Em ...

Traverse div elements using jQuery and showcase the text within them

I've got a setup like the one below. I want to use jQuery to grab each link and display its href right below it. Instead of writing code for each div individually, I'm looking for a solution that works for all divs with the 'col' class, ...

Switch between class and slider photos

I am currently having an issue toggling the class. Here is the code I am working with: http://jsfiddle.net/h1x52v5b/2/ The problem arises when trying to remove a class from the first child of Ul. I initially set it up like this: var len=titles.length, ...