katapofatico Posted May 16, 2016 Share Posted May 16, 2016 I'm developing a header tag module in order to include jquery validation plugin. I use Firefox browser.My first attempt works well ... private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group); // $this->group = 'header_tags' } ... but when I try to include another script... private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group); $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />', $this->group); } ... the browser only load the first one: jquery.validate.min.js ATTEMPTS1) If I switch the loading order... private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />', $this->group); $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group); } ... the browser only load the first one: messages_es.min.js2) I see that core modules sometimes include a breakline separator, then I try applying it... private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />' . PHP_EOL, $this->group); $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />' . PHP_EOL, $this->group); } ... the browser only load the first one: jquery.validate.min.js3) Using "\n" instead of PHP_EOL, as other modules... private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />' . "\n", $this->group); $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />' . "\n", $this->group); } ... the browser only load the first one: jquery.validate.min.js4) Importing another JS file: private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group); $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/jquery.scrollTo.min.js" />', $this->group); } ... the browser only load the first one: jquery.validate.min.js5) Using the jquery version associated to the query Validation 1.15. I disabled jquery import on template_top and then ... private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/lib/jquery.js" />', $this->group); $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />', $this->group); } ... the browser only load the first one: jquery.js6) Import each JS file from distinct modules: 6.A ) Importing jquery.validate.min.js on ht_noscript.php core module... function execute() { global $oscTemplate; $oscTemplate->addBlock('<noscript><div class="no-script"><div class="no-script-inner">' . tep_output_string(MODULE_HEADER_TAGS_NOSCRIPT_TEXT) . '</div></div></noscript>', $this->group); $oscTemplate->addBlock('<style>.no-script { border: 1px solid #ddd; border-width: 0 0 1px; background: #ffff90; font: 14px verdana; line-height: 2; text-align: center; color: #2f2f2f; } .no-script .no-script-inner { margin: 0 auto; padding: 5px; } .no-script p { margin: 0; }</style>', $this->group); // My hack: $oscTemplate->addBlock('<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />', $this->group); } 6.B ) ... and importing validation language file on my module: private function _includeValidation() { $oscTemplate->addBlock('<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />', $this->group); } ... ¡and this works! Experiments lead to me to consider that the problem is in my header tag module file, but it's made from another core header tag module, and it's simple... Has anyone encountered anything like this? Any clue, path will be so appreciated: I'm very frustrated, hours debugging :( Thanks! :pray: Link to comment Share on other sites More sharing options...
♥mattjt83 Posted May 16, 2016 Share Posted May 16, 2016 @@katapofatico You can paste your modules code here so we can look at it but you could also do something like.... $output = '<script type="text/javascript" src="ext/modules/validation/jquery.validate.min.js" />'; $output .= '<script type="text/javascript" src="ext/modules/validation/localization/messages_es.min.js" />'; $oscTemplate->addBlock($output, $this->group); Also make sure inside your function you include global $oscTemplate; Matt Link to comment Share on other sites More sharing options...
katapofatico Posted May 16, 2016 Author Share Posted May 16, 2016 @@mattjt83 Thanks for help: I didn't check your idea!... but it doesn't works :( My code whith your idea is here: <?php class ht_template_top_general { var $code = 'ht_template_top_general'; var $group = 'header_tags'; var $title; var $description; var $sort_order; var $enabled = false; function ht_template_top_general() { $this->title = MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_TITLE; $this->description = MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_DESCRIPTION; if (defined('MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS')) { $this->sort_order = MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_SORT_ORDER; $this->enabled = (MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS == 'True'); } } function execute() { global $PHP_SELF, $oscTemplate; switch ($PHP_SELF) { case FILENAME_CHECKOUT_SHIPPING_ADDRESS: { $validationJs = '<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />'; $validationJs .= '<script type="text/javascript" src="amantis/ext/modules/validation/localization/messages_es.min.js" />'; $oscTemplate->addBlock($validationJs, $this->group); } } } function isEnabled() { return $this->enabled; } function check() { return defined('MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS'); } function install() { tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Ajustes generales de Amantis sobre la plantilla', 'MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS', 'True', 'Ajustes generales de Amantis sobre la plantilla', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); } function remove() { tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { return array('MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_STATUS', 'MODULE_HEADER_TAGS_TEMPLATE_TOP_GENERAL_SORT_ORDER'); } } Link to comment Share on other sites More sharing options...
♥mattjt83 Posted May 16, 2016 Share Posted May 16, 2016 @@katapofatico Try this function execute() { global $PHP_SELF, $oscTemplate; if ( basename( $PHP_SELF ) == 'checkout_shipping_address.php' ) { $validationJs = '<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />'; $validationJs .= '<script type="text/javascript" src="amantis/ext/modules/validation/localization/messages_es.min.js" />'; $oscTemplate->addBlock($validationJs, $this->group); } } Matt Link to comment Share on other sites More sharing options...
♥mattjt83 Posted May 16, 2016 Share Posted May 16, 2016 I would also change var $group = 'header_tags'; to var $group = 'footer_scripts'; Matt Link to comment Share on other sites More sharing options...
katapofatico Posted May 16, 2016 Author Share Posted May 16, 2016 @@katapofatico Try this function execute() { global $PHP_SELF, $oscTemplate; if ( basename( $PHP_SELF ) == 'checkout_shipping_address.php' ) { $validationJs = '<script type="text/javascript" src="amantis/ext/modules/validation/jquery.validate.min.js" />'; $validationJs .= '<script type="text/javascript" src="amantis/ext/modules/validation/localization/messages_es.min.js" />'; $oscTemplate->addBlock($validationJs, $this->group); } } This is not the problem: current page is correctly detected, the first import works. Thanks anyway :) I would also change var $group = 'header_tags'; to var $group = 'footer_scripts'; Yes, I have been playing with this variable, and the problem continue :( Link to comment Share on other sites More sharing options...
♥mattjt83 Posted May 16, 2016 Share Posted May 16, 2016 OK, so the "problem continues". You are saying the scripts are not on the page if you view the source or they just are not functioning properly? As far as the code... I think the switch() in this case is a waste. Matt Link to comment Share on other sites More sharing options...
burt Posted May 16, 2016 Share Posted May 16, 2016 $validationJs = '<script src="amantis/ext/modules/validation/jquery.validate.min.js"></script>'; $validationJs .= '<script src="amantis/ext/modules/validation/localization/messages_es.min.js"></script>'; If that still does not work... $validationJs = '<script src="amantis/ext/modules/validation/jquery.validate.min.js"></script><script src="amantis/ext/modules/validation/localization/messages_es.min.js"></script>'; Link to comment Share on other sites More sharing options...
burt Posted May 16, 2016 Share Posted May 16, 2016 Also be aware that sometimes you code: src="amantis/ext/modules and sometimes: src="ext/modules Make sure that the path is a true reflection of where the file is located. Link to comment Share on other sites More sharing options...
katapofatico Posted May 17, 2016 Author Share Posted May 17, 2016 Thanks @@mattjt83 for your attempts and @@burt for the solution: it's was my fault: simply bad markup of <script> element!. Thanks! :thumbsup: Link to comment Share on other sites More sharing options...
katapofatico Posted May 17, 2016 Author Share Posted May 17, 2016 @@burt I don't know if is convenient to tag this as "solved" or something like this. Link to comment Share on other sites More sharing options...
burt Posted May 17, 2016 Share Posted May 17, 2016 Click "mark solved". Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.