swordfish
swordfish

Reputation: 959

Angularjs: how to detect min and max value of input numbers

I am trying to detect the minimum and maximum values of number type input field, so if the user increased the value, an ajax request get send, and so on for the max value.

Here is my code:

<input type="number" name="amount" id="amount" min="minNumber"
       max="maxNumber" value="{{value['qty']}}"
       data-product="{{value['id']}}"
       ng-blur="isValid(true)"
       ng-change="isValid(false)"
       ng-model="level.num">
$scope.minNumber = 1,
$scope.maxNumber = 99,
$scope.addedToCart = false

$scope.isValid = function () {
    if( ($scope.level.num < $scope.maxNumber) || ($scope.level.num > $scope.minNumber && blurMode)) {
        $scope.tooMany = true;
        $scope.level.num = $scope.minNumber;
    }
};

Upvotes: 0

Views: 1115

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222682

You should not pass any parameter to your function from template, and use only ng-blur in your case no need of ng-change unless you want to check for each text change

  ng-blur="isValid()"

Upvotes: 1

Related Questions