Example of a custom event

PHOTO EMBED

Fri Mar 22 2024 14:38:11 GMT+0000 (Coordinated Universal Time)

Saved by @MrSpongeHead

handleCodeChange(event) {
        let codeLength = event.target.value.length;
        
        if(codeLength === 6) {
            const selectedEvent = new CustomEvent("showvalidatebutton", {
                detail: {
                    codeReceivedFromCustomer: event.target.value,
                    codeSentToCustomer: this.completeCode.toString()
                }
            });
            this.dispatchEvent(selectedEvent);
        } else {
            this.dispatchEvent(new CustomEvent('hidevalidatebutton'));
        }
    }
content_copyCOPY

This particular example was used to pass details from a chile to a parent lwc component. The "showvalidatebutton" is used in the HTML as "onshowvalidatebutton".