In the file js/services.admin.js, the Drupal behaviors could be run multiple times, but the code doesn't handle this properly since it doesn't have .once() after the selectors. When the behaviors run multiple times, what you get is a very large number of checkboxes, because $(this).append(groupCheckbox); is called repeatedly. The extra checkboxes also break saving of the form.

To quote from an answer on Stack Overflow:

Drupal.behaviors is not simply a replacement for jQuery.ready since the latter only runs once (when DOM is ready for manipulation): behaviors can be fired multiple times during page execution and can be run whenever new DOM elements are inserted into the document.

Adding .once() will ensure that when an element has been processed, it won't be processed again.

In addition, I also noticed that the variable timeout doesn't seem to be used, but I'm not really sure what it was for so I left it.

Comments

solideogloria created an issue. See original summary.

solideogloria’s picture

StatusFileSize
new1.1 KB
solideogloria’s picture

Issue summary: View changes
solideogloria’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: services-js-missing-once-3052316-2.patch, failed testing. View results

solideogloria’s picture

Status: Needs work » Needs review

Only failed testing because the D7 branch itself failed 15 tests.

solideogloria’s picture

Priority: Normal » Major
StatusFileSize
new19.98 KB

I confirmed that removing the patch I created still affects the checkboxes in 7.x-3.25.

Lots of checkboxes

solideogloria’s picture

This is quite easy to test. All you have to do is call Drupal.attachBehaviors(someNode) on the resources page. So a custom module that attaches a behavior applying to the page, then calling attachBehaviors will do it.

See this link for Drupal documentation on jQuery $.once().

tyler.frankenstein’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.49 KB

In the file js/services.admin.js, the Drupal behaviors could be run multiple times...

You're right, thank you for the patch!

I also noticed that the variable timeout doesn't seem to be used...

Thank you for pointing this out, I've removed the unused variable.

I've included the updated patch for reference.

tyler.frankenstein’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.