How can I eliminate error messages from ng-repeat filter?

I am using Angular to validate a multi-page form consisting of HTML templates. Is there a way to selectively display specific error messages using $setValidity and ng-repeat with a string filter? If not, do you have any suggestions on how I can achieve this?

My goal is to capture errors, use $setValidity, and then show only certain error messages based on the page of the form where the error occurred.

Below is the Angular validation code snippet:

 ///TEAM DATA
    if (!$scope.formData.TeamContactFirstName) {
            $scope.signupform.$setValidity('TEAM: Please provide a Team Contact First Name', false)
            $scope.failedForms.team = true;
            isValid = false;
        }
        if (!$scope.formData.TeamContactLastName) {
            $scope.signupform.$setValidity('TEAM: Please provide a Team Contact Last Name', false)
            $scope.failedForms.team = true;
            isValid = false;
        }
//PROJECT BASICS
       if (!$scope.formData.Title) {
            $scope.signupform.$setValidity('BASICS: Please provide a project title.', false)
            $scope.failedForms.basics = true;
            isValid = false;
        }
if (!$scope.formData.ProjectLocation) {
        $scope.signupform.$setValidity('BASICS: Please provide the location of the project', false)
        $scope.failedForms.basics = true;
        isValid = false;
    }

Here is the relevant repeater code for displaying errors:

<div ng-show="signupform.$invalid" class="alert-box alert radius">
    <ul>
        <li ng-repeat="(key, errors) in signupform.$error">

            <ul>
                <li ng-repeat="e in errors"><strong>{{ key }}</strong>.</li>
            </ul>
        </li>
    </ul>
</div>

I am looking for a solution to only display the TEAM DATA errors within this repeater. Is there a way to apply a filter to achieve this?

Answer №1

An interesting way to utilize the $setValidity function:

<div ng-show="signupform.$invalid" class="alert-box alert radius">
    <ul>
        <li ng-repeat="(key, errors) in signupform.$error">

            <ul>
                <li ng-repeat="e in errors" ng-if="key.indexOf('TEAM:') == 0"><strong>{{ key }}</strong>.</li>
            </ul>
        </li>
    </ul>
</div>

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

Creating wrapped text in Three.js

Is there a way to wrap a Text3d object around a 3D or 2D Path in Three.js? I have looked into some tutorials for r.49 of Three.js and it appears that the current version does not have support for this feature. While I am able to create the text and extru ...

Guide to sending a POST request using AJAX within a Chrome Extension

I have encountered an issue with making an ajax call on my webpage. It works perfectly within my domain, but as soon as I navigate to a different domain, it fails with an error 406. This is for a closed system where users are aware that they are being trac ...

Efficient method for preserving dependent dropdown selections with Select2 and Ajax

I'm currently working on a script that dynamically populates the state dropdown menu based on the selected country id. Everything seems to be functioning correctly, but I've encountered an issue where I can only save the country selection using h ...

What is the best way to restructure this deeply nested JSON information?

I'm working with the payload structure of my API and I want to format the data in a way that allows for dynamic display on the frontend without hardcoding column names. Currently, I am using DRF, axios, and react-redux, but I feel like I may need to d ...

Setting up RouteConfig in ASP.NET MVC for AngularJS can be done by defining the routes in the

I need help with setting up angular routing for my asp.net mvc app. My goal is to redirect all requests for localhost/users/ to the index page so that I can utilize angular's client side route, with the exception of localhost/users/add which will use ...

Unable to convert multiple strings into integers using parseInt

Though seemingly straightforward, I couldn't figure out why I was unable to solve it. I'm attempting to convert a string to an integer from JSON data. It successfully converts the first object, but for some reason fails with the second one: HTM ...

Incorporate a different address using $location.path(path); and submit the ng-form

I have a form: <form name="myForm" ng-submit="save(myObject)"> ... <button type="submit" class="btn btn-primary" ng-click="changeLocation('/railway-connection')">Save </button> </form> My goal is to perform two actions w ...

Managing JSON responses from a server using Javascript

I have encountered various similar issues, but none of them have provided a solution for my specific question. On my server, I generate a JSON string and place it in the response: List<String> list = getSomeList(); JSONArray jsArray = new JSONArray( ...

Uncovering the Mystery Behind the Repetitive Execution of useEffect in Next.js

I am working on a Time Tracking feature for my Next.js application. In the ./app/components/TimeTracking.tsx file, I have implemented the following component: 'use client'; import React, { useEffect, useState } from 'react'; import { u ...

What is the best way to dynamically swap out an image within an element?

Is there a way to dynamically replace this image without deleting the HTML SVG element and re-rendering it? xlink:href="http://missosology.info/forum/download/file.php?avatar=11666_1307312313.jpg" CODE: https://jsfiddle.net/bfv17f0e/ <svg class="clip ...

Guide on invoking helper.js from nodeJs using angular controller

Currently, I'm working with an Angular controller, $http.get("/videos?sessionId="+helpers.isAuthenticated.then(function(res){ console.log(res); }); The above function is being denied access at the moment because it requires calling a function is ...

Identifying the conclusion of a folder being dropped in vanilla JavaScript

I am working on determining when a directory tree has been completely traversed after being dropped onto a page. My goal is to identify the point at which the next process can begin once the entire folder and its sub-directories have been processed by the ...

What is the procedure for extracting both the previous and updated values from the dynamic autocomplete feature when utilizing md-selected-item-change in Angular Material?

Currently, I'm working with Angular Material's autocomplete feature and am interested in retrieving the previous value when an item is changed. Due to the dynamic addition of the autocomplete directive on the web page, utilizing $watch threads m ...

Converting JavaScript JSON into a PHP array

When working with Javascript, I create an array using the following code: cachePHP = "'lat':'" + (Number(upDataItems[2])).toFixed(5)+"'"; cachePHP = cachePHP + ",'lon':'" + (Number(upDataItems[3])).toFixed(5)+"' ...

Invoking a child component's function while displaying the child component within a v-if directive in Vue

I'm looking to execute the method of a child component. It seems like developers often use the $nextTick function to handle data processing once all child components have been rendered. However, I'm facing an issue with calling the child compone ...

Avoiding double tapping to zoom on Chrome Android while using the desktop version of a website

Is there a way to disable zooming when double clicking in Google Chrome with the desktop site enabled? I attempted to use <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> without success. I al ...

Guide to selecting elements within the <md-dailoge-container> AngularJS 2 component using Selenium

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Converting Excel to HTML using codebeautify.org</title> </head> <body> <!DOCTYPE html> <html> <head> <meta charset="U ...

Why is it necessary to execute all tasks in JavaScript within functions that are invoked by the HTML?

I often find it frustrating that global variables cannot be easily defined, and it's a bit of a nuisance. I wonder why the code outside functions that are called doesn't execute? For instance, if I trigger the myFunction function from HTML, this ...

Guide to accessing JSON APIs by utilizing a link within another API that contains JSON data linking to yet another JSON file

Searching for a Solution to Fetch Data from a Specific URL and Display it on a New Screen I have successfully called the API using the following link: - Completed After receiving JSON data, I was able to populate my DataTable. - Completed Upon clicking a ...

What steps can be taken to automatically focus on the first field and select its contents when a user clicks on a link?

HTML: <div class="control-group"> <label class="control-label" for="some-id-1"><a href="http://example.com/some-id-1" target="_blank">Text1</a></label> <div class="controls"> <input type="text" id="so ...