Jump to content

BO - product detail - extra tab - jquery does not work


Recommended Posts

Hi, I am trying to create a new module in prestashop 1.6.1.23, I want to use a jquery in the back office, on a product detail tab. To create the tab, I use a hookDisplayAdminProductsExtra function. The jquery is loaded and seems to be working. However, if I try to use a simple thing, like hiding an element, nothing happens.

Simple scenario:

The hook function

public function hookDisplayAdminProductsExtra()
{
   return $this->display(__FILE__, '/views/templates/admin/j_product_tab.tpl');
}  

he template

<div class="aaa" id="abc">test</div>

The script

window.onload = function() {
    $(".aaa").hide();
}

The result is: in a product detail, there is an extra tab. On the tab, there is a div with a word "test" in it. But it remains visible.

Performing a test by adding

if (window.jQuery) {  
    alert("OK");
} else {
    alert("not OK");
}

brings the desired result => an alert with "OK", so the jquery itself works. But since the product detail page uses a lot of other scripts, I have a suspition, that the scripts from my module are being somehow "blocked", "overriden"... It seemed to me, that switching the product detail tabs reloads the content of all other tabs, so I tried to run the script only when the extra tab is active.

So I used a workaround in the script:

var a = document.getElementById('abc');
a.onmouseover = doHide;

function doHide() {
   $(".aaa").hide();
}

Using this workaround, if I access the product page, switch to the extra tab and move a mouse over the element, the script runs successfully and the element hides. But I need to perform a more complicated things in the script, that doesn't run even when using this workaround. So I need to find the root cause.

Does someone have an experience with this particular area (product detail) and using jquery? Any help will be greatly appreciated.

Thank you!

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...