Vivek
Vivek

Reputation: 13298

How to check if the form field is enabled or disabled in AngularJS controller

In an AngularJS controller, how do I check if a particular field is enabled or disabled? I have looked to the documentation of AngularJS but I didn't found any form field property to indicate the enabled/disabled state of a field.

Upvotes: 2

Views: 5792

Answers (2)

greatcricket
greatcricket

Reputation: 31

Angular's jqLite supports prop(). So if you check the .prop('disabled') it should return a boolean with your answer.

Upvotes: 3

devqon
devqon

Reputation: 13997

Create a variable on your controller and use it on your form:

controller:

$scope.fieldDisabled = true;

$scope.submitForm = function(){
    alert("Disabled: " + $scope.fieldDisabled);
}

view:

<form ng-submit="submitForm()">
    <input type="text" ng-model="myModel" ng-disabled="fieldDisabled" />

    <input type="submit" value="Submit" />
</form>

<button ng-click="fieldDisabled = !fieldDisabled">Toggle disable</button>

JSFIDDLE

Upvotes: 2

Related Questions