Checkall does not trigger onChange event

vgarvardt - March 10, 2009 - 18:08
Project:Checkall
Version:6.x-2.0
Component:JavaScript
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Your setCheckboxes() JS function implementation does not trigger onChange() event for checkboxes and I need this for my project.
I changed your function a little so now it's more jQuery'sh and triggers change event.

Here is updated function.

  function setCheckboxes(state) {
    $('input:checkbox', checkBoxes).each(function() { $(this).attr('checked', state).change(); });
  }

#1

markus_petrux - March 11, 2009 - 13:46

How about this?

  function setCheckboxes(state) {
    $('input:checkbox', checkBoxes).each(function() { this.checked = state; $(this).change(); });
  }

...it needs a bit less resources to execute than using jQuery to alter the checkbox status, plus this is compatible with all browsers, AFAIK.

#2

vgarvardt - March 12, 2009 - 13:34

This will work too.
If you want you can use mixed code style. As for me I don't think that setting attribute using jQuery API takes much time.

#3

markus_petrux - March 22, 2009 - 17:56
Category:bug report» feature request
Status:needs review» fixed

Well, I ended up committing a slightly different version of this.

$('input:checkbox', checkBoxes).attr('checked', state).change();

There's no need to use the jQuery each() iterator, and it is now 100% jQuery-ish.

I have also added blur() effect to click events. I'll pack a new release with these changes that should be available as soon as the packaging system proceeds.

Also, I've changed to issue status to "Feature request" as this was not really a bug.

And then... I'm going to write a new version that will also work in tables, where more than one set of checkboxes exist. I'll leave than one in DEV stage for a while...

#4

markus_petrux - March 22, 2009 - 17:56
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.