简体   繁体   中英

Validation number with min/max parameters

There are two fields. I need one was smaller than the second, and the second more than the first, and at the same time passed validation.

However, when entering the first number is not saved in model (saved as undefined), as no pass the validation condition "max"

Important to me is keyboard input instead of buttons

somebody can help me solve this problem?

<td><input type="number" class="form-control input-sm" ng-model="item.low" max="{{item.high-1}}" required></td>
<td><input type="number" class="form-control input-sm" ng-model="item.high" min="{{item.low+1}}" required></td>

Have you tried initializing the values of item.low and item.high in the controller?

 <!DOCTYPE html> <html data-ng-app> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script> <link rel="stylesheet" href="style.css" /> <script src="script.js"></script> </head> <body ng-init="item.low=0;item.high=1;"> <input type="number" class="form-control input-sm" ng-model="item.low" max="{{item.high-1}}" required> <input type="number" class="form-control input-sm" ng-model="item.high" min="{{item.low+1}}" required> <p>item.high={{item.high}}</p> <p>item.low={{item.low}}</p> </body> </html> 

it was easier than I thought

I just deleted test for max in the first INPUT, he was unnecessary and validation is successful and the data is correct

<td><input type="number" class="form-control input-sm" ng-model="item.low" required></td>
<td><input type="number" class="form-control input-sm" ng-model="item.high"  min="{{item.low+1}}" required></td>

ty all for help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM