wet-boew / wet-boew

Web Experience Toolkit (WET): Open source code library for building innovative websites that are accessible, usable, interoperable, mobile-friendly and multilingual. This collaborative open source project is led by the Government of Canada.

Home Page:https://wet-boew.github.io/wet-boew/index-en.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Can't get the load event to trigger

eduardosilveira-hub opened this issue · comments

I was reading through the documentation (https://wet-boew.github.io/v4.0-ci/docs/ref/tables/tables-en.html), but nothing I try gives me the result I need. I want to execute some tasks on the load of the datatable, but it just doesn't work for me.

@duboisp Can you give me a hand?

$(".wb-tables").on("wb-ready.wb-tables", function( event ) {
    alert('Loaded');
});

Are there any gotchas I need to know? thanks!

@eduardosilveira-hub your test code do work as expected.

But your are probably seeing an error in your browser console about "$ is not defined" like:

image

That error means jQuery is not loaded yet.

To fix that issue, you simply need to put your custom code after the inclusion of the "wet-boew.js" script.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.js"></script>
<script src="../../../wet-boew/js/wet-boew.js"></script>
<script>
	$(".wb-tables").on("wb-ready.wb-tables", function( event ) {
		alert('Loaded');
	});
</script>

or, not recommended for production but could help for testing/developing/quick exploration, you can use an hack where your are delaying the code execution with a setTimeout instruction. You need to ensure the delay is long enough to have the jQuery and WET library loaded and ready in memory. But that hack are not going to work for listening the wb-ready event because that even is closely connected with the wet-boew plugin initialization process which start automatically.

You actually opened my eyes to initializing the datatable! such a rookie mistake! Thanks for the answer @duboisp !!