Topic: JavaScript resources are not always loaded with XMLHttpRequest

Kevin priority asked 4 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 4 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 4 months ago

Can you make an example please?

Kamila Pieńkowska staff commented 4 months ago

Sure. Here it is:

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.


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



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