1

I got it all working fine, except one thing. I need myForm to be $valid = true if

  • all inputs are filled
  • no inputs are filled

and $valid = false if

  • some, but not all, inputs are filled

Note this is all inside an ng-repeat and an ng-form subform.

How would I do it? Is there any way?

1 Answer 1

1

Simply add the ng-required directive to all fields in myForm.

E.g. <input type="text" name="myInput" ng-required="isRequired()" />.

The isRequired function should then simply return true if at least one of the form fields contains a value, otherwise false.

If this doesn't work, then there's information you've left out - so in that case please provide more information about your HTML and JS code (I'm only mentioning this because I see you've tagged the question with ng-repeat, which might make the scenario slightly different than the vanilla one you've described in your question).

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

3 Comments

Yeah forgot to mention that this is inside an ng-repeat and ng-form subform. I'll look into that isRequired, but require is not the only validation I'd have there. There will also be email and stuff..
Well, the provided answer should still work - but exactly how to implement it depends on how you've coded your form.
OK. Thanks. I'd be glad to help with your problem if you can formulate it more precisely. Have you added another question for it? Another solution would be to make your own custom validation directive for forms and add it to each ngForm.

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.