Drupal 8 Form API supports form states, that allow to ad jQuery behaviors with form API. To do that, however, you need to convert the element's parents array into the notation like field_body[subform]. This utility function concatenates the element's parents array into the required notation.
When working with the hook altering the widget form, you often need to get the widget state to get the entities behind the form as well as additional information that is stored in the state. Here is the utility function for it.