Jump to content

Edit History

Navid59

Navid59

Hi All

I writing a Module in Prestashop 1.7 and I will need to use simple jQuery in Back-office of my Module ,but I can't use jquery .
I tried $this->context->controller->addJquery(); in hookBackOfficeHeader(), but it's not working.

From, what I read I understand in Back-office is not supported jQuery , but I couldn't believe that .
So I was talked  with an  Expert in Prestashop
Thankful to @razaro to guide me , he recommended me to use like this :

 public function hookActionAdminControllerSetMedia()
    {
        if (get_class($this->context->controller) == 'AdminDashboardController') {
            if (method_exists($this->context->controller, 'addJquery')) {
                $this->context->controller->addJquery();
            }

            $this->context->controller->addJs($this->_path.'views/js/'.$this->name.'.js');
            $this->context->controller->addJs(
                array(
                    _PS_JS_DIR_.'date.js',
                    _PS_JS_DIR_.'tools.js'
                ) // retro compat themes 1.5
            );
        }
    }


And now , is worked , I have my own JS & jQuery 
But the problem is Ordering now .

My JS file should be called after jQuery  NOT Before jQuery

 


...
<script type="text/javascript" src="/prestashop/modules/mytest/views/js/back.js"></script>
<script type="text/javascript" src="/prestashop/js/jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/prestashop/js/jquery/jquery-migrate-1.2.1.min.js"></script>
...

And i Think because of the orders i receive this error Uncaught ReferenceError: $ is not defined at back.js:53

What I have in line 53 is 

 

$('#my-filed-name').on('change', function () {
    alert('TEST ALERT');
});

Is any idea how to change the order of JS file in back-end?

Thank you


 

Navid59

Navid59

Hi All

I writing a Module in Prestashop 1.7 and I will need to use simple jQuery in Back-office of my Module ,but I can't use jquery .
I tried $this->context->controller->addJquery(); in hookBackOfficeHeader(), but it's not working.

From, what I read I understand in Back-office is not supported jQuery , but I couldn't believe that .
So I was talked  with an  Expert in Prestashop
Thankful to @razaro to guide me , he commandeered me to use like this :

 public function hookActionAdminControllerSetMedia()
    {
        if (get_class($this->context->controller) == 'AdminDashboardController') {
            if (method_exists($this->context->controller, 'addJquery')) {
                $this->context->controller->addJquery();
            }

            $this->context->controller->addJs($this->_path.'views/js/'.$this->name.'.js');
            $this->context->controller->addJs(
                array(
                    _PS_JS_DIR_.'date.js',
                    _PS_JS_DIR_.'tools.js'
                ) // retro compat themes 1.5
            );
        }
    }


And now , is worked , I have my own JS & jQuery 
But the problem is Ordering now .

My JS file should be called after jQuery  NOT Before jQuery

 


...
<script type="text/javascript" src="/prestashop/modules/mytest/views/js/back.js"></script>
<script type="text/javascript" src="/prestashop/js/jquery/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/prestashop/js/jquery/jquery-migrate-1.2.1.min.js"></script>
...

And i Think because of the orders i receive this error Uncaught ReferenceError: $ is not defined at back.js:53

What I have in line 53 is 

 

$('#my-filed-name').on('change', function () {
    alert('TEST ALERT');
});

Is any idea how to change the order of JS file in back-end?

Thank you


 

×
×
  • Create New...