0

 Hello, is there a simple way to disable validation while an ajax request is downloading the model from the server?

Let's say I have this input.

<input type="text" class="form-control" id="FieldName" name="FieldName"
  ng-model="model.thefield" required ng-maxlength="100">

And this model which does not pass the validation initially:

$scope.model = {}

So, the input is invalid until the request finishes:

$http.get('/some/url')
    .then(function (response) {
        $scope.model = response.data;
    });

Is there a way to disable validation until this request has finished. I currently set the model to a valid value initially. Example:

$scope.model = {
    thefield: "loading"
}
2
  • What do you mean by 'disable validation'? Do you want to stop validation so that required and ng-maxlength do not work until the request is finished? Or you want to validate input field until the request is finished and after that it should not validate input? Commented Oct 29, 2015 at 10:18
  • "Do you want to stop validation so that required and ng-maxlength do not work until the request is finished?" this one. Commented Nov 3, 2015 at 9:15

1 Answer 1

2

You can try to change your required to ng-required="yourBool" and then write

$http.get('/some/url')
  .then(function (response) {
    $scope.yourBool = true;
    $scope.model = response.data;
  });
Sign up to request clarification or add additional context in comments.

Comments

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.