Navid59 Posted October 20, 2020 Share Posted October 20, 2020 (edited) 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 Edited October 20, 2020 by Navid59 (see edit history) Link to comment Share on other sites More sharing options...
JBW Posted October 22, 2020 Share Posted October 22, 2020 I'm using $this->context->controller->setMedia(); in hookDisplayBackOfficeHeader before $this->context->controller->addJS(). This loads jQuery before my JS file. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now