Disable submit button after one click in angularJS
Asked Answered
O

4

6

I would like to disable button after one click.

Code:

<button id="submitRequest" class="btn btn-primary btn-active"
        ng-disabled="!frmRequest.$valid||!r.DataUseAgreement||(!chkBMT&&!chkOncore&&!chkCAISIS&&!chkLIMS&&!chkFCR)"
        ng-click="SaveData()">
  <i class="fa fa-save"></i> Submit
</button>

How to disable this one after one click?

Thanks!

Obscurity answered 27/7, 2016 at 16:24 Comment(2)
what do you mean by one click?Priory
all inputs, checkboxes and selects add requiredImpoverished
J
7

Simple. You write to element a bit of javascript, like onclick="this.disabled=true" .

<button id="submitRequest" onclick="this.disabled=true" class="btn btn-primary btn-active" ng-disabled="!frmRequest.$valid||!r.DataUseAgreement||(!chkBMT&&!chkOncore&&!chkCAISIS&&!chkLIMS&&!chkFCR)" ng-click="SaveData()"><i class="fa fa-save"></i> Submit</button>
Java answered 27/7, 2016 at 16:31 Comment(1)
This will disable the button one click,but it doesnt allow form submission too for first click.Langue
L
5

Disabling button after one click

<input type="submit" name="Submit" class="btn btn-primary"
value="Submit" ng-disabled="button.disabled"/>

In Controller,where u submit the form just add

scope.button={};
scope.button.disabled=true;

This disables the button after one click form submission

Langue answered 28/3, 2017 at 7:27 Comment(0)
D
2

In your SaveData() function, add below line in beginning of function:

$scope.saving=true;

then, in your ng-disabled condition, add additional condition:

saving||!frmRequest.$valid||!r.DataUseAgreement||(!chkBMT&&!chkOncore&&!chkCAISIS&&!chkLIMS&&!chkFCR)
Decasyllable answered 27/7, 2016 at 17:37 Comment(0)
P
1

It is quite straight forward. You just have to add one more Boolean condition in your ng-disable statement.

 <button class="btn btn-info" ng-click="ctrl.isSubmit()" ng-disabled="ctrl.submitClicked">Submit</button>

And in your Controller

var vm=this;
vm.submitClicked=false;

vm.isSubmit= function(){
vm.submitClicked= true;
}

Here is a Plunker that I made for you

Pythia answered 10/7, 2017 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.