Automatically Wire a Fragment's Custom Event to the Parent Container
When working with a fragment custom event set up to emit payload to the parent container, you can automatically wire the event to the fragment's parent container (say, a page or dynamic container). Autowiring an event makes it easier to create an event listener on the parent container—you won't have to define an event handler in HTML—and allows the event listener on the parent container to be invoked whenever the event is fired on the fragment.
- Create a custom event that emits its payload to the parent container, then enable it for autowiring on the parent container.
- In the fragment's Events tab, create a custom event that emits its payload to the parent container (Emit event to container must be selected and parameters added to specify the payload that will be passed to the parent container).
- Enter an Auto Wire Event ID, which will identify the event's listener on the parent container once created.
- Create a listener for the autowired event on the fragment's immediate parent container. If your fragment is used on a page (for example), create an event listener on the page's Event Listeners tab; if it is used in a layout's form template, create the event listener on the layout's Event Listeners tab.