0

I am trying to keep my submit button disabled until form is HTML valid which I have managed to do like so:

<button type="submit" class="btn" ng-disabled="mainPaymentForm" ng-click="disableButton()"><%button%></button>

In my controller I have this:

// Disable form on submit
$scope.disableButton = function(){
        $scope.button = "Loading...";
        $scope.submit.disable = true; // This doesn't work
}; 

Overall I am just trying to keep button disabled until valid / and prevent multiple submit clicks once valid.

Thanks

1 Answer 1

1

I figured it out:

HTML code

ng-disabled="mainPaymentForm.$invalid || clickDisable"

JS controller code

// this will unable button if form becomes valid
$scope.$watch('mainPaymentForm.$invalid', function(){
        $scope.clickDisable = false;
});

// this will disable it on click
$scope.disableButton = function(){
        $scope.button = "Loading...";
        $scope.clickDisable = true;
}; 
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.