3

I would like to handle clicks on disabled radio button and its label using Angularjs.

//html
<div ng-app>
  <div ng-controller="TempCtrl">
    <label data-ng-click="handleClick()">
      <input type="radio" value="1" data-ng-disabled="true">
      Value 1
    </label>
    <label data-ng-click="handleClick()">
      <input type="radio" value="2" >
      Value 2
    </label>
  </div>
</div>

//javascipt
function TempCtrl($scope) {

  $scope.handleClick = function() {
    alert('handleClick')
  };

}

Here is jsfiddle. So when user clicks on disabled radio, alert should appear. How can I do that?

tiktak
  • 1,801
  • 2
  • 26
  • 46
  • What exactly you need? Can you please elaborate more.. It looks interesting.. – Pankaj Parkar Aug 09 '17 at 11:25
  • @PankajParkar When user clicks on disabled radio button and input, notice should be displayed. When user clicks on not disabled radio, some calculations are performed. All the logic in the handleClick function. I simple left alert to simplify things. – tiktak Aug 09 '17 at 11:29

2 Answers2

2

See the below snippet for answer

<html ng-app="myApp">
<head>
 <title></title>
</head>
<body ng-controller="myCtrl">
 <label for="input1" data-ng-click="handleClick('input1')">
      <input name="input1" id="input1" type="radio" value="1" data-ng-disabled="true">
      Value 1
    </label>
    <label for="input2" data-ng-click="handleClick('input2')">
      <input name="input2" id="input2" type="radio" value="2" >
      Value 2
    </label>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("myApp", []);

app.controller('myCtrl', ['$scope', function ($scope) {
 $("#input1").prop('disabled',true).css('pointer-events','none');
$scope.handleClick = function(id) {
    var disabled=$("#"+id).attr('disabled');
    if(disabled=='disabled'){
    alert("disabled")
    }
  };
}]);

</script>
</body>
</html>
phani indra
  • 243
  • 1
  • 10
1

According to this: Event on a disabled input

you are not able.

One approach would be to not to disable it, and set up a class:

 [class.notReallyDisabled]="w/e"

And then use CSS to change its aspect.

lilezek
  • 6,976
  • 1
  • 27
  • 45
  • In this case value will be set on input and I will need to revert it. I'm interested in more elegant solution actually. But if I dont' find anything, I'll have to go this way. – tiktak Aug 09 '17 at 11:31