0

I have an ng-repeat to iterate over form fields.

The problem is, if I have an invalid form I don't get any feedback. I don't see the span, nor do I see has-error get applied to the div.

I must be missing something simple, can anyone see what it is?

Here's the ng-repeat code:

<div ng-repeat="i in items">
    <ng-form novalidate class="user-form" name="userForm">
        <div class="form-group has-feedback" ng-class="{'has-error':userForm.userInput.$invalid}">
            <label class="control-label">{[{ i.item }]}</label>
            <input-field item="i"></input-field>
            <span ng-show="userForm.userInput.$invalid">TEST</span>
        </div>
    </ng-form>
</div>

Which generates an entry like this:

    <div ng-repeat="i in items">
        <ng-form novalidate="" class="user-form" name="userForm">
            <div class="form-group has-feedback" ng-class="{'has-error':userForm.userInput.$invalid}">
                <label class="control-label">Username</label>
                <input name="userInput" class="form-control" type="text" ng-model="item.answer" placeholder="Username" required>
                <span ng-show="userForm.userInput.$invalid" class="ng-hide">TEST</span>
            </div>
        </ng-form>
    </div>

1 Answer 1

0

You want create more than one "userForm"? If not you can change it to

  <ng-form novalidate class="user-form" name="userForm"> <div ng-repeat="i in items">
    <div class="form-group has-feedback" ng-class="{'has-error':userForm.userInput.$invalid}">
        <label class="control-label">{[{ i.item }]}</label>
        <input-field item="i"></input-field>
        <span ng-show="userForm.userInput.$invalid">TEST</span>
    </div> </div>
</ng-form>

Hope it helps.

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

4 Comments

Yeah I need multiple userForm's - my understanding was that Angular validation works on form names; hence why I need to have multiple forms.
The "userForm" should dynamid name right? name="userForm" shoud change to name="{{}}"
@b85411 yes, Angular validation works by referencing form names, however in your case, you are creating a form for every control, which doesn't seem like it would normally make sense.
@Claies I was following the lead from stackoverflow.com/a/19860312/2884981

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.