simontabor / jquery-toggles

jQuery plugin to make easy toggle buttons
http://simontabor.com/labs/toggles
MIT License
362 stars 67 forks source link

Handle disabled checkbox #38

Closed alterphp closed 9 years ago

alterphp commented 10 years ago

Hi,

I'm not sure but it seems that jquery-toggles does not handle disabled checkbox input.

It might be a future enhancement...

simontabor commented 10 years ago

Could you explain this in a bit more detail for me please?

alterphp commented 10 years ago

Sorry for this laconic message...

When a checkbox is disabled, I think the "toggle" behavior should not apply. So I guess "click" event must firstly check if the clicked input is enabled or not.

penguinpowernz commented 9 years ago

I have accounted for this on a work project, for the click side anyway. I have forked and plan to do a pull request but am going on an epic road trip so won't be able to do a pull request till next month.

This code starts on line 160 and is as simple as this:

Toggles.prototype.bindEvents = function() {
  var self = this;

  // evt handler for click events
  var clickHandler = function(e) {

    // is the toggle disabled?
    if ( $(e['target']).parents(".toggle.disabled").size() > 0 ) {
      e.preventDefault();
      return false;
    }

So this toggle will not be toggleable:

<div class="toggle disabled toggles-modern"></div>

Assign it dynamically via the .addClass() and .removeClass() jQuery methods.