Topic: JavaScript resources are not always loaded with XMLHttpRequest

Kevin priority asked 8 months ago


Hello everyone,

do you know why it can be that when you implement something with XHR, JavaScript resources are sometimes missing in the reloaded part and sometimes everything is loaded normally? Mostly form elements such as select are implemented

Sincerely, Kevin


Kamila Pieńkowska staff answered 8 months ago


Comonents are auto initiated on the page load. If you add component after that you need to initiate them with JS. It is better to remove autoinit attributes from components that are going to be added via XHR and initiate them with JS. Optionaly you can run getOrCreateInstance method on them.


Kevin priority commented 8 months ago

Can you make an example please?


Kamila Pieńkowska staff commented 8 months ago

Sure. Here it is: https://mdbootstrap.com/snippets/standard/kpienkowska/6004094

Example is dropdown (it doesn't matter if it was there from the begining since it is not initiated), if you comment out JS code it won't work.

You need to run this JS code after you add HTML elements to the page. It won't result in unnecessary double init.



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

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 7.1.0
  • Device: Computer
  • Browser: Firefox
  • OS: Windows 11
  • Provided sample code: No
  • Provided link: No