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!
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.
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.
//This will make all read-only check boxes truly read-only $('input[type="checkbox"][readonly]'). on("click. readonly", function(event){event. preventDefault();}).
Clicking on the master checkbox selects all checkboxes; and unchecking it, deselects all checkboxes.
Try
event.stopPropagation();
http://jsfiddle.net/DrKfE/3/
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(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With