Currently working on an application and I d like to list the fields sections that fail validation to direct the user to look for errors in the right tab Error

0 votes

I tried to leverage form.$error to do so; yet I don't fully get it working?

If validation errors occur inside a ng-repeat, e.g.:

<div ng-repeat="url in urls" ng-form="form">
  <input name="inumber" required ng-model="url" />
  <br />
</div>

Empty values result in form.$error containing the following:

{ "required": [
  {
    "inumber": {}
  },
  {
    "inumber": {}
  }
] }

On the other hand, if validation errors occur outside this ng-repeat:

<input ng-model="name" name="iname" required="true" />

The form.$error object contains the following:

{ "required": [ {} ] }

yet, I'd expect the following:

{ "required": [ {'iname': {} } ] }
Feb 7, 2020 in Angular by kartik
• 37,520 points
1,270 views

1 answer to this question.

0 votes

I made a function that you pass the form to. If there are form errors it will display them in the console.

 It shows the objects so you can take a look. I put this in my save function.

function formErrors(form){
  var errors = [];
  for(var key in form.$error){
    errors.push(key + "=" + form.$error);
  }
  if(errors.length > 0){
    console.log("Form Has Errors");
    console.log(form.$error);
  }
};

Hope this code can resolve your error!!

answered Feb 7, 2020 by Niroj
• 82,800 points

Related Questions In Angular

0 votes
1 answer

How to change the value of an Observable in TypeScript Angular?

To change the value of an Observable ...READ MORE

answered Feb 21, 2025 in Angular by Kavya
849 views
0 votes
1 answer

How to develop a directive that modifies element styles based on form validation status?

Here's a concise directive that automatically applies ...READ MORE

answered Apr 10, 2025 in Angular by anonymous
500 views
0 votes
1 answer
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,800 points

edited Jan 21, 2020 by Niroj 2,295 views
+1 vote
1 answer

What is css box module?

Hey, All the element present in html follows ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,800 points

edited Jan 21, 2020 by Niroj 2,155 views
0 votes
3 answers

Explain the difference between visibility:hidden; and display:none?

display:none means that the tag in question will ...READ MORE

answered Dec 14, 2020 in Web Development by Gitika
• 65,730 points
122,320 views
+1 vote
1 answer

How to access the Angularjs scope of a particular html element from our console?

Hello, You should follow the below steps:-- 1.Compile and ...READ MORE

answered Jan 21, 2020 in Web Development by Niroj
• 82,800 points

edited Jan 21, 2020 by Niroj 4,149 views
0 votes
1 answer

What is the service that is used to configure the UI-Router and ngRoute in AngularJs?

Routing comes into play whenever you want ...READ MORE

answered Feb 11, 2020 in Angular by anonymous
• 82,800 points
1,184 views
0 votes
1 answer

What does this construct look like in Typescript for Angular ?

Hello @kartik, try this. selectChildren(data, $event) { ...READ MORE

answered Sep 8, 2020 in Angular by Niroj
• 82,800 points
1,310 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP