Topic: Autocomplete dropdown items custom template onclick attributes are removed

umch777 free asked 2 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 :

Dawid Wajszczuk staff answered 2 years ago


You can add this code

asyncAutocomplete.addEventListener('open.mdb.autocomplete', ()=>{
    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,

umch777 free commented 2 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 2 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 You can add this way every attribute that you need.

umch777 free commented 2 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 !!

Please insert min. 20 characters.


Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.



Specification of the issue

  • User: 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