Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-readonly not working in angular checkbox

Can I use ng-readonly directive in a checkbox?

The checkbox is writable even after it is decorated with ng-readonly.

Html:

<input type="checkbox" ng-model="model" ng-readonly="test" /> {{model}}

Controller:

myApp.controller('MyCtrl', function($scope) {
    $scope.test = true;
});

Added Fiddle

like image 224
Praveen Prasannan Avatar asked Nov 18 '15 10:11

Praveen Prasannan


People also ask

How do I make a checkbox readonly?

//This will make all read-only check boxes truly read-only $('input[type="checkbox"][readonly]'). on("click. readonly", function(event){event. preventDefault();}).

How do I make a checkbox readonly in AngularJS?

AngularJS ng-readonly DirectiveThe ng-readonly directive sets the readonly attribute of a form field (input or textarea). The form field will be readonly if the expression inside the ng-readonly attribute returns true. The ng-readonly directive is necessary to be able to shift the value between true and false .

How do I make a checkbox not clickable in HTML?

$(':checkbox[readonly]'). click(function(){ return false; });

How do I style a disabled checkbox?

You can't style a disabled checkbox directly because it's controlled by the browser / OS. However you can be clever and replace the checkbox with a label that simulates a checkbox using pure CSS. You need to have an adjacent label that you can use to style a new "pseudo checkbox".


2 Answers

if you want to disable it use this:

<input type="checkbox" ng-disabled="true" ng-model="test" />
like image 167
macrog Avatar answered Sep 27 '22 23:09

macrog


If you like to have it "more" visible, you can always use a little javascript trick:

<input type="checkbox" ng-model="model" onclick="return false;" />
like image 23
Michael Overbay Avatar answered Sep 27 '22 21:09

Michael Overbay