2

I'm trying to disable a button if the form in which it is in isn't valid. However, for some reason the $error array associated with the form is holding a list of ten useless errors (so the button is always off), all with the following shape:

{
    "$validators": {},
    "$asyncValidators": {},
    "$parsers": [],
    "$formatters": [
        null
    ],
    "$viewChangeListeners": [],
    "$untouched": true,
    "$touched": false,
    "$pristine": true,
    "$dirty": false,
    "$valid": false,
    "$invalid": true,
    "$error": {
        "required": true
    },
    "$name": "",
    "$options": null
}

As you can see, with an empty $name property, and with no other helpful information.

4
  • Please post your html from Form tag down. Commented Apr 29, 2015 at 14:30
  • I didn't because is too much big, with a couple of ngIncludes even. I perfectly understand that without it is more complicated to try to figure out the problem, but I think there must be some "recognizable" mistake that causes this $name property to be empty. What I can ensure is that I don't have that number of required inputs in my form. I must have like 5 in total, 6 at maximum if perhaps I'm forgetting one, but for sure not 10, and for sure not 10 empty ones (the errors persist even filling the fields, and the model properly changes). Commented Apr 29, 2015 at 15:18
  • i'm afraid without it, it's going to be too difficult. Cut it down to the most important elements. form, input, submit, any elements with validation. do a plunk? Commented Apr 29, 2015 at 15:22
  • I'll try soon. Another thing I can say is that it was working no so much time ago. I first thought that it was because of the textAngular plugin, but removed it and had the same problem. Commented Apr 29, 2015 at 15:34

1 Answer 1

1

I've found a solution, although not to the originally posted problem. The issue was that I was using ngIf to hide some parts of the form, containing inputs, intentionally. But at some point the magic idea of changing this to ngShow came to my mind, and I just didn't realize the consequences until some time after. So there was the problem, Angular considers the hidden elements but not the non-existing ones for form validation. It sounds logic and reasonable.

But, this was the first time I started to debug the form properties in this application, and have no idea about why the $name's are empty. Could it be that I'm using the "controller as" syntax instead of attaching the stuff to the $scope? Maybe is because of this, but anyway I think this is a downside of Angular somehow.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.