[Skip to main content](#vessel-content)

#   Javascript isn't loaded by onHikashopAfterDisplayView at the address view

##

- **[alin](/forum/user/51267-alin "View alin's Profile")**
- [![alin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar51267.png)](/forum/user/51267-alin "View alin's Profile") Topic Author
- [ Offline](/forum/user/51267-alin)

Less More

- Posts: 117
- Thank you received: 6
-
-

8 years 5 months ago -  8 years 5 months ago [\#293200](#293200) by [alin](/forum/user/51267-alin "View alin's Profile")  *[Javascript isn't loaded by onHikashopAfterDisplayView at the address view](/forum/31-development/894818-javascript-isnt-loaded-by-onhikashopafterdisplayview-at-the-address-view#293200 "I'm creating a plugin, I use onHikashopAfterDisplayView trigger to add javascript to needed page. At the checkout view all is working fine but at the address view it doesn't work. I'm a beginner :)...")* was created by *[alin](/forum/user/51267-alin "View alin's Profile")*

I'm creating a plugin, I use onHikashopAfterDisplayView trigger to add javascript to needed page. At the checkout view all is working fine but at the address view it doesn't work. I'm a beginner ![:)](/media/kunena/emoticons/3.png ":)") Help me, please, to find the reason. Here is my code:
Code:

&lt;?php defined('_JEXEC') or die('Restricted access'); ?&gt;&lt;?php class plgHikashopDadata_address_suggestions extends JPlugin { // protected $autoloadLanguage = true; function plgHikashopDadata_address_suggestions(&amp;$subject, $config){ parent::__construct($subject, $config); } function onHikashopAfterDisplayView(&amp;$view) { $plugin = JPluginHelper::getPlugin('hikashop', 'dadata_address_suggestions'); $plg_params = new JRegistry(); $plg_params-&gt;loadString($plugin-&gt;params); $document = JFactory::getDocument(); if($view-&gt;getName() === 'checkout') { $document-&gt;addStyleSheet('https://cdn.jsdelivr.net/npm/suggestions-jquery@17.12.0/dist/css/suggestions.min.css','text/css'); $document-&gt;addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js','text/javascript'); ?&gt;&lt;!--[if lt IE 10]&gt;&lt;?php $document-&gt;addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.1/jquery.xdomainrequest.min.js','text/javascript'); ?&gt;&lt;![endif]--&gt;&lt;?php $document-&gt;addScript('https://cdn.jsdelivr.net/npm/suggestions-jquery@17.12.0/dist/js/jquery.suggestions.min.js','text/javascript'); $document-&gt;addScriptDeclaration(' function suggest() { function showPostalCode(suggestion) { $("#' . $plg_params-&gt;get('post_code_field_id') . '").val(suggestion.data.postal_code); } function clearPostalCode(suggestion) { $("#' . $plg_params-&gt;get('post_code_field_id') . '").val(""); } $("#' . $plg_params-&gt;get('full_address_field_id') . '").suggestions({ token: "' . $plg_params-&gt;get('token') . '", type: "ADDRESS", onSelect: showPostalCode, onSelectNothing: clearPostalCode }); } Oby.registerAjax("checkoutBlockRefresh", suggest); '); } if($view-&gt;getName() === 'address') { $document-&gt;addStyleSheet('https://cdn.jsdelivr.net/npm/suggestions-jquery@17.12.0/dist/css/suggestions.min.css','text/css'); $document-&gt;addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js','text/javascript'); ?&gt;&lt;!--[if lt IE 10]&gt;&lt;?php $document-&gt;addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.1/jquery.xdomainrequest.min.js','text/javascript'); ?&gt;&lt;![endif]--&gt;&lt;?php $document-&gt;addScript('https://cdn.jsdelivr.net/npm/suggestions-jquery@17.12.0/dist/js/jquery.suggestions.min.js','text/javascript'); $document-&gt;addScriptDeclaration(' $(document).ready(function () { function showPostalCode(suggestion) { $("#' . $plg_params-&gt;get('post_code_field_id') . '").val(suggestion.data.postal_code); } function clearPostalCode(suggestion) { $("#' . $plg_params-&gt;get('post_code_field_id') . '").val(""); } $("#' . $plg_params-&gt;get('full_address_field_id') . '").suggestions({ token: "' . $plg_params-&gt;get('token') . '", type: "ADDRESS", onSelect: showPostalCode, onSelectNothing: clearPostalCode }); }); '); } } }

P.S. I've attached the plugin. Its main purpose is to add javascript code to the checkout and address views for integration with a third-party service.

---

Sorry for my English, it's not my native language.

Last edit: 8 years 5 months ago by [alin](/forum/user/51267-alin "View alin's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NDgxOC1qYXZhc2NyaXB0LWlzbnQtbG9hZGVkLWJ5LW9uaGlrYXNob3BhZnRlcmRpc3BsYXl2aWV3LWF0LXRoZS1hZGRyZXNzLXZpZXc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26400
- Thank you received: 4079
-
- [](http://obsi.dev)
-

8 years 5 months ago [\#293222](#293222) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Javascript isn't loaded by onHikashopAfterDisplayView at the address view](/forum/31-development/894818-javascript-isnt-loaded-by-onhikashopafterdisplayview-at-the-address-view#293222 "I'm creating a plugin, I use onHikashopAfterDisplayView trigger to add javascript to needed page. At the checkout view all is working fine but at the address view it doesn't work. I'm a beginner :)...")*

Hello,

You need to check if the view you're targeting do have the " displayView " variable enable.
Please note that if you want to add some javascript in the header ; you can also use regular Joomla triggers (like the one which is called before the head processing)

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NDgxOC1qYXZhc2NyaXB0LWlzbnQtbG9hZGVkLWJ5LW9uaGlrYXNob3BhZnRlcmRpc3BsYXl2aWV3LWF0LXRoZS1hZGRyZXNzLXZpZXc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[alin](/forum/user/51267-alin "View alin's Profile")**
- [![alin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar51267.png)](/forum/user/51267-alin "View alin's Profile") Topic Author
- [ Offline](/forum/user/51267-alin)

Less More

- Posts: 117
- Thank you received: 6
-
-

8 years 5 months ago -  8 years 5 months ago [\#293229](#293229) by [alin](/forum/user/51267-alin "View alin's Profile")  Replied by *[alin](/forum/user/51267-alin "View alin's Profile")* on topic *[Javascript isn't loaded by onHikashopAfterDisplayView at the address view](/forum/31-development/894818-javascript-isnt-loaded-by-onhikashopafterdisplayview-at-the-address-view#293229 "I'm creating a plugin, I use onHikashopAfterDisplayView trigger to add javascript to needed page. At the checkout view all is working fine but at the address view it doesn't work. I'm a beginner :)...")*

> Jerome wrote: You need to check if the view you're targeting do have the " displayView " variable enable.

Hello,
what does this means? Where can I check this?

This code at the view "checkout" (first screenshot) works: Code:

if($view-&gt;getName() === 'checkout') { some code works }

But at the view "address" (second screenshot) it doesn't work: Code:

if($view-&gt;getName() === 'address') { some code doesn't work }

> Jerome wrote: Please note that if you want to add some javascript in the header ; you can also use regular Joomla triggers (like the one which is called before the head processing)

I need to insert some js only at the pages where HikaShop address fields are present.

---

Sorry for my English, it's not my native language.

- [ ![--GoogleChrome2018-05-2719.20.39.png](/forum/attachment/43789) ](/forum/attachment/43789 "...2719.20.39.png") [ ](/forum/attachment/43789?download=1 "...2719.20.39.png")
- [ ![-GoogleChrome2018-05-2719.21.34.png](/forum/attachment/43790) ](/forum/attachment/43790 "...2719.21.34.png") [ ](/forum/attachment/43790?download=1 "...2719.21.34.png")
- [ ![-Administration-Views-GoogleChrome2018-05-2719.24.52.png](/forum/attachment/43791) ](/forum/attachment/43791 "...2719.24.52.png") [ ](/forum/attachment/43791?download=1 "...2719.24.52.png")

Last edit: 8 years 5 months ago by [alin](/forum/user/51267-alin "View alin's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NDgxOC1qYXZhc2NyaXB0LWlzbnQtbG9hZGVkLWJ5LW9uaGlrYXNob3BhZnRlcmRpc3BsYXl2aWV3LWF0LXRoZS1hZGRyZXNzLXZpZXc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

8 years 5 months ago [\#293253](#293253) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Javascript isn't loaded by onHikashopAfterDisplayView at the address view](/forum/31-development/894818-javascript-isnt-loaded-by-onhikashopafterdisplayview-at-the-address-view#293253 "I'm creating a plugin, I use onHikashopAfterDisplayView trigger to add javascript to needed page. At the checkout view all is working fine but at the address view it doesn't work. I'm a beginner :)...")*

Hi,

1. If you look in components/com_hikashop/views/checkout/view.html.php you have the line:
public $triggerView = array('hikashop','hikashoppayment','hikashopshipping');
This line allow plugins of that group to use the onHikashopAfterDisplayView and onHikashopBeforeDisplayView triggers.
If you look in components/com_hikashop/views/address/view.html.php, there is no $triggerView which means that these triggers are not available for the views from "address".
So you would have to add the line:
public $triggerView = true;
in that file and then these triggers would be called there.

2. As Jerome said, since you're only adding javascript to the header, it's better to use this trigger of Joomla in a plugin of the group "system":
[ docs.joomla.org/Plugin/Events/System#onBeforeCompileHead](https://docs.joomla.org/Plugin/Events/System#onBeforeCompileHead)
You just need to change your check on $view-&gt;getName to use JInput:
[ docs.joomla.org/Retrieving\_request\_data\_using\_JInput](https://docs.joomla.org/Retrieving_request_data_using_JInput)
And check on $jinput-&gt;get("option") == "com_hikashop" and $jinput-&gt;get("ctrl") == "checkout"

The following user(s) said Thank You: [alin](/forum/user/51267-alin "View alin's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NDgxOC1qYXZhc2NyaXB0LWlzbnQtbG9hZGVkLWJ5LW9uaGlrYXNob3BhZnRlcmRpc3BsYXl2aWV3LWF0LXRoZS1hZGRyZXNzLXZpZXc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[alin](/forum/user/51267-alin "View alin's Profile")**
- [![alin's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar51267.png)](/forum/user/51267-alin "View alin's Profile") Topic Author
- [ Offline](/forum/user/51267-alin)

Less More

- Posts: 117
- Thank you received: 6
-
-

8 years 5 months ago -  8 years 5 months ago [\#293316](#293316) by [alin](/forum/user/51267-alin "View alin's Profile")  Replied by *[alin](/forum/user/51267-alin "View alin's Profile")* on topic *[Javascript isn't loaded by onHikashopAfterDisplayView at the address view](/forum/31-development/894818-javascript-isnt-loaded-by-onhikashopafterdisplayview-at-the-address-view#293316 "I'm creating a plugin, I use onHikashopAfterDisplayView trigger to add javascript to needed page. At the checkout view all is working fine but at the address view it doesn't work. I'm a beginner :)...")*

Thank you very much for detailed explanation - now it's working like needed. I faced jQuery compatibility issues with Chosen library that HikaShop loads but I think it's other story... At now plugin does its job - puts js code to head.

---

Sorry for my English, it's not my native language.

Last edit: 8 years 5 months ago by [alin](/forum/user/51267-alin "View alin's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NDgxOC1qYXZhc2NyaXB0LWlzbnQtbG9hZGVkLWJ5LW9uaGlrYXNob3BhZnRlcmRpc3BsYXl2aWV3LWF0LXRoZS1hZGRyZXNzLXZpZXc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.073 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
