0

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;
    }
};
0

1 Answer 1

1

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

6 Comments

Oh yea that's did the job, but is there any AngularJS directives to detect whether the Keyup or Keydown pressed ?? i need to separate two ajax requests, so it depends on which key has the user pressed.
ng-keyup is for keyboard, is there any way to check if the user increased the value by pressing on the up arrow or down arrow ?
you need to use the keycode by getting the user input
do i need to get the equivalent keycode to check whether up or down has been pressed? it's more comfort to check if he clicked one of the arrows !!
|

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.