BrMe
BrMe

Reputation: 315

Angular Validation for input depends on another input

I have a list of json objects. Each object has minage and maxage.

I want to ng-repeat on this object and display input to enter the minAge and input for maxAge.

I want to add validation for the fields:

Example fiddle

Upvotes: 0

Views: 1547

Answers (1)

Artem Petrosian
Artem Petrosian

Reputation: 2954

You can use min and max arguments within your inputs to achieve this:

<div ng-repeat="range in ages">
    minAge: <input type="number" min="{{ages[$index-1]['MaxAge']}}" max="{{range.MaxAge}}" ng-model="range.MinAge" />

    maxAge: <input type="number" min="{{range.MinAge}}" ng-model="range.MaxAge" />
</div>

Upvotes: 1

Related Questions