What I'm trying to do is to invoke some javascript after a webform is successfully submitted by ajax.
To do that I followed this advice and created an EventSubscriber to intercept ajax response and add my custom command there. The problem is that on some reason I can't check if the webform is submitted (data are sent) or not.
public function onResponse(FilterResponseEvent $event) {
if($event->getResponse() instanceof WebformSubmissionAjaxResponse &&
$event->getResponse()->getWebformSubmission()->isCompleted()) {
$event->getResponse()->addCommand(new MyCustomCommand());
}
}
The problem is in isCompleted() method which always returns false on some reason. Actually I checked other methods from WebformSubmissionInterface and in this my event subscriber this WebformSubmission entity always looks empty (getters return nothing) and geState() always returns "STATE_UNSAVED" not depending if a webform is successfully sent of failed on validation.
What I'm missing? Is anything I'm doing wrong here? Or maybe are there any other method to achive same goal?