It would be nice to be able to listen for when items in the form builder are opened or closed. Currently, it is very difficult to accomplish similar things by binding to various click events due to the fact that many operations in form_builder.js return false;, which effective stops event propagation.

For example, when trying to integrate a WYSIWYG editor with the webform markup component, I was getting a JS error when editing the component because the WYSIWYG instance was not properly unset when the form builder item was closed.

This patch adds the following events that other scripts can bind to. All events pass the active element as an additional argument, if there is one:

  • formBuilder.setActive
  • formBuilder.closeActive
  • formBuilder.unsetActive
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Issue summary: View changes
Status: Active » Needs review

Thanks for the patch. Events would definitely be a good idea. The only question I think we should consider is where the event should be attached. Perhaps we could put it on the Form Builder wrapper, rather than the whole document? Document-wide events often seem a bit overkill, and may cause issues when you have multiple instances of something on a page (not that would be a problem with Form Builder I hope).

torotil’s picture

Status: Needs review » Needs work

I also think the element of the event should be narrowed down at least to the form_builder wrapper.

… due to the fact that many operations in form_builder.js return false;, which effective stops event propagation.

This is a bad thing in itself. So if think this should be addressed too. return false should be replaced with event.preventDefault() and only if it's really needed also with event.stopPropagation().

svax’s picture

Status: Needs work » Needs review
FileSize
1.61 KB

I updated the patch with the events attached to '.form-builder-wrapper'.

torotil’s picture

Status: Needs review » Needs work

Thanks for changing the element for the events. I still would reduce the occurences of return false; too. Maybe this could even substitute the explicit events.