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?

2
  • What exactly you need? Can you please elaborate more.. It looks interesting.. Commented Aug 9, 2017 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. Commented Aug 9, 2017 at 11:29

2 Answers 2

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>

Sign up to request clarification or add additional context in comments.

9 Comments

Still can't see alert when click on disabled input
just try the click on label
In my jsfiddle alert is displayed when i click on labels. The idea is to display alert when user clicks on disabled radio button.
i couldn't see any alert on your jsfiddle
My fault, there was a console.log. I updated original post with link to alert version.
|
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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.