Topic: Autocomplete dropdown items custom template onclick attributes are removed
umch777 free asked 3 years ago
Expected behavior
Autocomplete dropdown items custom template attributes should not be removed
Actual behavior
Autocomplete dropdown items custom template onclick attribute removed in final dropdown rendering, check the code using chrome inspect elements
*Resources (screenshots, code snippets etc.)*code : https://mdbootstrap.com/snippets/standard/umch777/3242821#js-tab-view
Dawid Wajszczuk staff answered 3 years ago
Hi,
You can add this code
asyncAutocomplete.addEventListener('open.mdb.autocomplete', ()=>{
setTimeout(()=>{
document.querySelectorAll('a').forEach((aTag)=>{
aTag.setAttribute('onclick', 'test()')})},10)
})
at the end of your JS file. You can also add some custom class to your a tags and make different query selector in order to prevent unwanted interaction with different elements on your site.
Keep coding,
Dawid
umch777 free commented 3 years ago
This workaround resolves onclick issue, but we cannot pass onclick arguments like id/name/value etc., and as attributes are removed we cannot find which a tag clicked on. This is still does not solve my current issue.
Is there a reason for removing attributes ? I also noticed that button tag removed completely.
Dawid Wajszczuk staff commented 3 years ago
To add functionality that you have asked for, we will need to rewrite most of this component. And we don't plan to do this in near future. But here is the snippet showing how to achieve most of requested things https://mdbootstrap.com/snippets/standard/d-wajszczuk/3246079. You can add this way every attribute that you need.
umch777 free commented 3 years ago
Thanks Dawid, that solves my issues. I did tried similar approach before with string concatenation which did not worked, but string interpolation worked.
Thanks for quick support !!
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB Standard
- MDB Version: MDB5 3.9.0
- Device: laptop
- Browser: Chrome
- OS: Mac
- Provided sample code: No
- Provided link: Yes