1

I am using the iCheck module for checkboxes, and the checkbox is initially hidden by the Webform module. Somehow, the Webform module also sets it to disabled while hidden, which is nice.

Once it gets shown, the disabled status is removed from the webform, but the iCheck module doesn't notice. Calling iCheck.update() fixes it, but I need to catch an event to do that.

Are there JavaScript events sent by a webform conditionals?

2 Answers 2

1

The Webform module for Drupal 8 is using Drupal's States API, which triggers custom events that are prefixed with 'state:*'.

Events include...

  • state:disabled
  • state:required
  • state:visible
  • state:checked
  • state:collapsed
2
  • Drupal's States API has not changed much since D7. I think these events or something very similar is still applicable.
    – jrockowitz
    Dec 5, 2017 at 19:15
  • 1
    I tried to catch state:visible (on body and html) but caught nothing. where does the event go ? or better, where is this documented ?
    – commonpike
    Dec 5, 2017 at 20:17
1

I've spent a while looking at this in D9 it seems the events that are used don't get propagated which is probably why this is not documented or used elsewhere.

Having tweaked the JS to emit events on a reasonably complex form it's not as useful as you would think. There are a lot of events pushed and it's not entirely clear what is happening internally (it may be more clear on a simple form)

An alternative that seems to be working is to listen for change events on the elements that you are interested in, then you can check the state (for example visible) and react to that. It's not ideal and you have to check for multiple changes but it does work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.