Wanted to provide an update here for anyone else that might stumble upon this thread with the same question.
jQuery events are executed in their own layer. While jQuery can pick-up on vanilla JS events, vanilla JS cannot listen for jQuery events. So, you will need to actually use jQuery to dispatch the events so that native event listeners can pick them up.
Example:
Let's say I have developed some vanilla JavaScript module that doesn't want to or need to know about jQuery. I have this code added in the Web Template or somewhere. But it DOES need to know when a date column on the Power Apps form changes.
If I included the following line of code here on the Basic Form or Web Page's JavaScript areas, every time a datetime 'dp.change' jQuery event occurs, the datetimepicker component will then dispatch a native vanilla JS event.
$('#liquid_form .datetimepicker').on('dp.change', function (ev) {
const relatedField = ev.target.previousElementSibling;
if (relatedField) {
const myEvent = new CustomEvent('datetimepicker-changed', {
bubbles: true,
detail: {
logicalName: () => relatedField.id
}
});
this.dispatchEvent(myEvent);
}
})
Here, we are using jQuery to identify all DateTime pickers on the page, and then dispatch a custom JS Custom Event. Notice here that I included a function in the Custom Event that will return the logical name of the Dataverse column. This is so that you can identify which Dataverse column is changed.
Native Javascript event listeners can pickup on this. For example:
document.addEventListener('datetimepicker-changed', function(e){
console.log(e.detail.logicalName())
});
Perfect! This allows my JS modules to be developed without needing to know anything about jQuery. If/when Microsoft decides to upgrade the Power Apps Portals from Bootstrap3/jQuery (or decides to no longer use the boostrap3-datetimepicker component for it's Date controls...), I will only need to adjust the Custom Event dispatcher rather than having to make changes to the JS module.
Cheers!