Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent checkbox from ticking/checking COMPLETELY

I have been asked to disable the "ticking" of a checkbox. I am not being asked to disable the checkbox, but to simply disable the "ticking".

In other words, a user will think that a checkbox is tickable, but it is not. Instead, clicking on the checkbox will cause a modal dialog to appear, giving the user more options to turn on or off the feature that the checkbox represents. If the options chosen in the dialog cause the feature to be turned on, then the checkbox will be ticked.

Now, the real problem is that for a split second, you can still see that the checkbox is being ticked.

I have tried an approach like this:

<input type='checkbox' onclick='return false' onkeydown='return false' />  $('input[type="checkbox"]').click(function(event) {     event.preventDefault();     alert('Break'); }); 

If you run this, the alert will appear, showing that the tick is visible (the alert is just there to demonstrate that it still does get ticked, in production, the alert is not there). On some users with slower machines and/or in browsers with slow renderers/javascript, users can see a very faint flicker (the flicker sometimes lasts for half a second, which is noticeable).

A tester in my team has flagged this as a defect and I am supposed to fix it. I'm not sure what else I can try to prevent the tick in the checkbox from flickering!

like image 768
Andrew Avatar asked May 15 '12 23:05

Andrew


People also ask

How do you disable a checkbox if it is checked?

Using attr() function attr('disabled'); This function also takes a parameter to specify the property or the task that the selected element or checkbox is applied to. Whereas this function specifies the property for the checkbox object and it is specified as “disabled” for disabling the checkbox object.

How do you stop a checkbox being checked in angular 8?

preventDefault() to stop checkbox from been toggled. You can event add some logic before $event. preventDefault() to determin whether the checkbox should be prevent from changing status.

How do I make a check box read-only?

//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 uncheck the select all checkbox?

Clicking on the master checkbox selects all checkboxes; and unchecking it, deselects all checkboxes.


2 Answers

Try

event.stopPropagation(); 

http://jsfiddle.net/DrKfE/3/

like image 175
Zoltan Toth Avatar answered Sep 24 '22 02:09

Zoltan Toth


Best solution I've come up with:

$('input[type="checkbox"]').click(function(event) {     var $checkbox = $(this);      // Ensures this code runs AFTER the browser handles click however it wants.     setTimeout(function() {       $checkbox.removeAttr('checked');     }, 0);      event.preventDefault();     event.stopPropagation(); }); 
like image 43
paulpooch Avatar answered Sep 22 '22 02:09

paulpooch