Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My code is the following :

<ng-form name="invitationForm">
<div ng-repeat="email in emails" ng-form='lineForm'>
    <div class="has-feedback" ng-class="{'has-error': lineForm.$invalid && lineForm.input, 'has-success': lineForm.input && !lineForm.$invalid}">
        <label class="control-label sr-only" for="inputSuccess">Input with success</label>
        <input ng-change="inputCheck($index)" id="inputSuccess" placeholder="Enter your friend's email" name="input" ng-model="email.value"  class="form-control input-mini" aria-describedby="inputSuccessStatus" type="email" />
    </div>
</div>
</ng-form>

What I want to do is have the div with class "has-feedback" have class "has-error" when the lineForm is invalid and the input is not empty. I put the condition lineform.$invalid && lineForm.input but lineForm.input doesn't seem to be working. I also tried lineForm.input.length to no avail.

Thanks

share|improve this question
1  
I think you are over complicating things. If you are using angular 1.3, read through yearofmoo's article on forms and validations - yearofmoo.com/2014/09/taming-forms-in-angularjs-1-3.html –  Scorpion-Prince Dec 4 '14 at 21:48

1 Answer 1

http://plnkr.co/edit/se8iBxlUK6J0oS8lUWTn?p=preview

I don't think you need to create that many forms. Check out this example (several elements with required input:

<form role="form" name="theform">

  <div ng-repeat="number in [1,2,3]">
    <input type="text" 
           name="{{$index}}" 
           ng-model="number" 
           required="" />
  </div>

  {{ theform.$valid ? 'yes, valid form' : 'no, invalid' }}

  <br/><br/>

  <div ng-repeat="element in theform">
    {{ element.$valid }}
  </div>

   <br/>
   Explore this:
   <br/><br/>
   {{ theform }}

</form>

For further examples on what you can do with the formController: https://docs.angularjs.org/api/ng/type/form.FormController

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.