Disable Button In AngularJS Using ng-disabled On It's First Page Load In ASP.NET MVC
Hello,
One might notice that during page load of an ASP.NET MVC application, the button with ng-disabled attribute and have values such as $invalid or $dirty does not disable the button. Thus, this will enable the user to submit the form with empty values to the controller method. In order to disable the button on page load, add $pristine values in the ng-disabled attribute such as the code below.
Original Code
Modified code with $pristine
One might notice that during page load of an ASP.NET MVC application, the button with ng-disabled attribute and have values such as $invalid or $dirty does not disable the button. Thus, this will enable the user to submit the form with empty values to the controller method. In order to disable the button on page load, add $pristine values in the ng-disabled attribute such as the code below.
Original Code
<input type="submit" id="btnAddEmployee" class="btn btn-primary" value="Save" ng-click="Save()" ng-disabled="AddEmp.fname.$dirty && AddEmp.fname.$invalid || AddEmp.lname.$dirty && AddEmp.lname.$invalid || AddEmp.salary.$dirty && AddEmp.salary.$invalid" />
<input type="submit" id="btnAddEmployee" class="btn btn-primary" value="Save" ng-click="Save()" ng-disabled="AddEmp.fname.$dirty && AddEmp.fname.$invalid || AddEmp.fname.$pristine || AddEmp.lname.$dirty && AddEmp.lname.$invalid || AddEmp.lname.$pristine || AddEmp.salary.$dirty && AddEmp.salary.$invalid || AddEmp.salary.$pristine" />
Comments
Post a Comment