coure2011
coure2011

Reputation: 42454

How to find out whether all inner ng-forms are valid or not?

I have html code like this

<div class="section1">
    <div ng-repeat="item in Objs1">
        <ng-form name="myForm">
            <input require name="expression" ng-model="item.exp" />
            <label ng-show="myForm.expression.$error.required" class="error">*-required</label>
        </ng-form>
    </div>
    <button ng-disabled="--if any myForm is invalid--">Add</button>
</div>
<div class="section2">
    <input require name="first" ng-model="firstName" />
    <input require name="first" ng-model="SecondName" />
</div>

How can I know --if any myForm is invalid--?

Upvotes: 0

Views: 34

Answers (1)

Michael Kang
Michael Kang

Reputation: 52847

ngForm can be nested. Just add an outer ngForm:

<ng-form name="parentForm">
<div ng-repeat="item in Objs">
    <ng-form name="myForm">
        <input require name="expression" ng-model="item.exp" />
        <label ng-show="myForm.expression.$error.required" class="error">*-required</label>
    </ng-form>
</div>
<button ng-disabled="parentForm.$invalid">Add</button>

</ng-form>

Upvotes: 2

Related Questions