Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

jQuery not working?

Hi all,

I'm using QlikView 11, and trying to make my own extension using RaphaelJS and jQuery. Developing in Aptana.

I can create a timeline in Raphael, but what's not working is adding a 'tooltip' on hover (which is why I need jQuery). Very elemental things don't seem to work and I'm wondering if I am doing this in the right way.

I have simplified my code to the following, could anyone look at it and see what is wrong?

jQuery is loaded, but the TipDiv element is not found, why?

----------------------------------------

Qva.LoadScript("/QvAjaxZfc/QvsViewClient.aspx?public=only&name=Extensions/MatthijsZ/HelloWorld/raphael-min.js", loadJQuery);

Qva.LoadCSS("/QvAjaxZfc/QvsViewClient.aspx?public=only&name=Extensions/MatthijsZ/HelloWorld/styles.css");

function loadJQuery()

{

          Qva.LoadScript("/QvAjaxZfc/QvsViewClient.aspx?public=only&name=Extensions/MatthijsZ/HelloWorld/jquery-1.7.1.min.js", onDoneLoadingScripts);

          if(!jQuery)

                         alert("Essential plugin (jquery) not loaded");

}

function onDoneLoadingScripts() {

          Qva.AddExtension('MatthijsZ/HelloWorld', function() {

                    try {

                              $(this.Element).append("<div id='tip'>jQuery is working</div>");

                              if($('tip').length == 0)

                                             alert("TipDiv not found"); // <-- why do I get this alert?

} catch(err) {

                              txt = "There was an error on this page.\n\n";

                              txt += "Error description: " + err.description + "\n\n";

                              txt += "Click OK to continue.\n\n";

                              alert(txt);

                    }

          }, false);

}

1 Solution

Accepted Solutions
ErikWetterberg

7 Replies
ErikWetterberg

Hi,

Try $('#tip') instead. You need to put a # before your id to make it work.

http://api.jquery.com/id-selector/

Erik

Not applicable
Author

Thanks!!

I knew it was something simple. I was thinking it was a Qlikview thing, never suspected to look at my jQuery code...

By the way, do you also know why the code is called twice on a refresh?

Alexander_Thor
Employee
Employee

We ship jquery together with qv11 so you dont need to reference it, if you dont need the latest version.

With qv11 you also have the possibility to push your external libs into an array and use the LoadExtensionScripts instead, will save you some typing

What might cause problems for you is that you append divs without any checks if the element already exists.

So any subsecvent updates in the qv app will fire your code again, appending another div and another div and another div

I usually just check for children length, not sure if that is the smartest way but it works

Not applicable
Author

Hi Alexander,

Thanks for the update, that will indeed save some typing

That is a problem, in my original code I clear the HTML, I agree, better would be to just check the DOM.

I was wondering, though, why Qlikview calls this code twice on a review? Is this standard practice?

Alexander_Thor
Employee
Employee

Well it _should_ not do that. The snippet below will only alert you once for each update for example.

However I've seen some strange behaviour in conjuction with the OnUpdateComplete method that will fire twice for a refresh of the page. I usually load my css before external scripts, not sure if that will have an impact.

Qva.AddExtension('Alert', function(){

          alert("Init");

})

ErikWetterberg

Hi,

I can't see anything in your code that would trigger double rendering, but what I have seen in other extensions is that you call methods that will change server state as part of the rendering code, like ClearSelections(). You should normally not do that.

The function you supply in the AddEextension() call is a rendering function. It should be called every time something happens that would mean you need to rerender the object, like slection change (that affects the underlying data), size change, change of properties etc.

Erik

Not applicable
Author

Hi Alexander and Erik, thanks for your replies. This gives me a bit more insight in the writing of QlikView extensions.