Is there a more efficient way to disable all form elements in a large form with multiple tabs when a specific condition is met? I could go with
<input ng-disabled="myCondition()">
, but it would require adding this code in many places, leading to potential code duplication. Instead, I opted for the following approach in my controller (using coffeescript).
$scope.$watch 'myCondition()', ->
if $scope.myCondition()
$('.my-form').find('input, select, textarea').attr('disabled', true)
else
$('.my-form').find('input, select, textarea').attr('disabled', false)
Although this method works, it may not be the most robust solution. If another scenario arises where a form element needs to be conditionally disabled, this implementation could cause unexpected behavior. What is the best practice for achieving this functionality? Could $compile
play a role?