0

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:

  • Max age should be bigger than Min age.
  • the Min age of the next pair of inputs should be lower than Max age of previous pair of inputs.

Example fiddle

2
  • the ìnput` tag is an angular js directive you can find all you need here : docs.angularjs.org/api/ng/input/input%5Bnumber%5D Commented May 20, 2015 at 9:42
  • 1
    the first validation can you writh: <input type="number" ng-model="range.MaxAge" min="{{range.MinAge}}"/> Commented May 20, 2015 at 9:42

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

10x.Thats what I need! but :for the first minAge I dont have any value in :ages[$index-1]['MaxAge'] , How can I check if no value, and put min=0 ?
@BrMe I think you can use something like this: {{range.MaxAge ? range.MaxAge : null}}
This is work for me :{{ages[$index-1].MaxAge || 0 }}

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.