Topic: Autocomplete dropdown items custom template onclick attributes are removed

umch777 free asked 1 year 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 1 year 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 1 year 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 1 year 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 1 year 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.

FREE CONSULTATION

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

Status

Answered

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