Form validation errors were detected

Currently, I am working with a formgroup that contains input fields with validations set up in the following manner:

<mat-form-field class="mat-width-98" appearance="outline">
                        <mat-label>Profession Occupation/ Job</mat-label>
                        <input matInput placeholder="Profession Occupation/ Job" formControlName="occupation"
                               (focusout)="onFocusOutEvent($event, 'occupation')"
                               [ngClass]="isMatched('occupation') ? '' : 'input-highlight'"
                               maxlength="{{moduleConfig.td_reg_occupation_length}}">
                        <mat-error *ngIf="dataEntryMainFormGroup.get('occupation').hasError('required') ">
                          {{msgConfig.td_data_entry_required_occupation}}
                        </mat-error>
                        <mat-error *ngIf="dataEntryMainFormGroup.get('occupation').hasError('invalidNameFormat') ">
                          {{msgConfig.td_registration_validation_invalid_occupation}}
                        </mat-error>
                      </mat-form-field>

The validation setup for 'occupation' is as follows:

      occupation: new FormControl('', [Validators.required, this.validationService.invalidNameFormat.bind(this)]),

An issue arises where these validations are triggered even when clicking on a different button in the UI, which should not be the case. The intended behavior is for the validations to only trigger when the field is outfocused.

It is important to note that I am currently working with tabs in this scenario.

Answer №1

After discovering a missing element in the solution provided earlier, I implemented the following steps:

In my component, there were multiple buttons and I realized that I had forgotten to specify the type attribute. Here is how it should look:

<button type="button">

Answer №2

To insert in HTML:

 <mat-error *ngIf="dataEntryMainFormGroup.get('occupation').hasError('required')&& 
     (dataEntryMainFormGroup.get('occupation').dirty || 
    dataEntryMainFormGroup.get('occupation').touched)
         ">
       {{msgConfig.td_data_entry_required_occupation}}
     </mat-error>

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

Tips on organizing all property options into an array of objects

I need to identify the array type of a specific property and use TypeScript typing for autocompletion. const arr = [{test:'option 1'},{test: 'option 2'}] type test = arr[number]['test'] let t:test = '' // will equal ...

Is it possible to identify in Next.js whether scrollRestoration was triggered, or if the back button was pressed?

I've been utilizing the scrollRestoration functionality within Next.js to save and restore the page position whenever a user navigates using the back button. However, I've encountered an issue with it not restoring the horizontal scroll position ...

Unable to save input from <from> in the React state object

I'm currently working on a project in reactjs where I need to store user input in the react state object. I followed an example from reactjs.com, but it seems like the input is not being stored in the state object as expected. class CreateMovieForm ex ...

Interval function failing to update information on Jade template

Currently, I am working on a Node app using Express and Jade. My aim is to retrieve JSON data from an API and have it refresh on the page periodically. To achieve this, I have created an empty div where I intend to inject the contents of a different route/ ...

Tips for unit testing an Angular Service that is primarily responsible for redirecting to an external page from the application

My service is responsible for redirecting to a separate login page since we are implementing login as a service. function redirectToMembership() { var returnURL = $location.host(); returnURL+="/#/Authorization"; $window.location.href=Environme ...

Encountering an unrecoverable SyntaxError while trying to deploy a website on Netlify

When using commands like npm start, npm run build, and pm2 start server.js, everything runs smoothly without any errors. However, I encounter an issue when trying to deploy my project on Netlify. The Chrome console displays the error: Uncaught SyntaxError: ...

Integrating information from an API into the Document Object Model

const url = `https://catfact.ninja/fact?max_length=140`; const getFact = () => { return fetch('https://catfact.ninja/fact?max_length=140') .then(res => res.json()) } const createFactDiv = (fact) => { const factContainer = documen ...

Components are not being displayed by React Router v4

Encountering an issue with React Router v4 where components are not being rendered correctly. Initially, when the application loads, the corresponding component for the URL is displayed. However, subsequent clicks on any Link do not result in the desired c ...

Trouble with top attribute functionality within animate function

Why does the top attribute in the animate function of JQuery not seem to work, while the opacity attribute functions correctly in the code snippet below? $(function() { $(window).on('scroll', function() { ...

Understand and extract data from a JSON array using Typescript

Here is a JSON response I received from a remote server: { "string": [ { "id": 223, "name": "String", "sug": "string", "description": "string", "jId": 530, "pcs": [{ "id": 24723, "name": "String", ...

Add a user to a guild using Discord API

Hello, I'm currently working on integrating the Discord API to automatically add users to a guild upon login. However, I keep encountering a 401 Unauthorized error and I'm unsure of the reason behind it. Below is a snippet of my code: const data ...

How do I execute 2 functions when the button is clicked?

<button id="take-photo"> Take Image</button> <button type="submit" value="Submit" >Submit </button> How can I trigger two tasks with a single button click? 1. Executing a function based on ID Next 2. Submitting the form with ...

Error: PrimeNG Treenode Component is having difficulty rendering the data

I'm currently working on a project in Angular 5 where I need to display data in a Treenode format. The data is coming from a service and is structured as follows (in object form): { "data": [ { "label": "Documents", ...

Switching classes in jQuery for Internet Explorer 8

I am attempting to update the color of a header when it reaches a certain scroll position. I have implemented this script using jQuery: var $document = jQuery(document), $element = jQuery('#header'), className = 'red'; $docume ...

Display an icon within an HTML element when the content inside it exceeds its boundaries

Looking to display a copy to clipboard icon when the content inside a div overflows I am using ngFor to iterate through four divs, and if any of those divs is overflowing, I want to show an icon specific to that respective div. <div *ngFor div of Four ...

Tips for enhancing the TypeScript definition of Material UI 3 theme by integrating the Material UI pickers theme

Trying to enhance the Material-UI theme with the Typescript typings of Material-UI-Pickers for the latest versions listed here: "@material-ui/core": "^3.9.2", "material-ui-pickers": "^2.2.1", A note on the bottom of the Material UI picker page mentions t ...

Disable the ability to click on the indicators in the Bootstrap carousel

Seeking assistance with customizing tweeters bootstrap Carousel functionality. I have removed the controls and now want to switch slides according to my own logic while displaying slide indicators. How can this be achieved? Preferably seeking a solution ...

Ways to create dynamic functionality with JavaScript

I need to iterate through the document.getElementById("b") checked in a loop. Is this achievable? How can I implement it? <img class="img-responsive pic" id="picture" src="images/step1.png"> <?php //get rows query ...

Using AJAX along with the append method to dynamically add identical HTML content multiple times to a single element

Although I have successfully implemented most of the desired functionality with this JavaScript code, there is a persistent bug that is causing unnecessary duplicates to be created when appending HTML. Detecting Multiples The problem lies in the fact tha ...

What is the best way to determine the data type of one property in an array of objects based on another property

I have been working on creating a straightforward parser that relies on rules provided by the constructor. Everything seems to be running smoothly, but there are some issues with data types. interface RuleBase { parse(text: string, params: Record<stri ...