Hi Mattia,
Thanks for that.!
I checked on my end, works well for initial render.
However when I tried to navigate back to create ticket page, getting below error.
A not very elegant solution is to change “const” to “var” and not stop the observer.
I hope this fixes it!
var observer = new MutationObserver(function (_) {
console.log('new mutation!')
const emailField = document.getElementById('helpdesk_ticket_email')
if (emailField) {
emailField.disabled = true
// observer.disconnect(); // Stop observing once the field is found and disabled
return
}
})
window.onload = function () {
console.log('onload!')
observer.observe(document.body, { childList: true, subtree: true })
}
It seems code doesn’t get executed after initial render. This would work for static pages as every time we click on something page gets render.
I am not sure if we can use same approach in Single page application. Function doesn’t get call at all for the subsequent renders.
Perhaps you can try embedding the script in a common layout page, such as the header or footer. But I don’t know if this could create any problem if there is a field with the same id in another page.
Thanks man It works
I guess this Mutation Observer is tracking all the changes from initial page load.
Only thing now I wanted to confirm is, are there any side affects on performance / storage. considering large count of people using support portal day in day out.