5

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!

georgeawg
  • 48,608
  • 13
  • 72
  • 95
sravs17991
  • 51
  • 1
  • 1
  • 4

4 Answers4

6

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>
EddNewGate
  • 527
  • 5
  • 19
  • 2
    This will disable the button one click,but it doesnt allow form submission too for first click. – Hema Mar 28 '17 at 07:12
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

Hema
  • 988
  • 1
  • 16
  • 38
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)
Dev Shah
  • 302
  • 1
  • 7
0

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

KIA
  • 182
  • 2
  • 9