Domanda

I want an autocomplete field in my page, and my code is right, but it doesn't work. When I used Joomla 2.5 then it worked but I had to change to Joomla 3.2 and it isn't working now. I use these js files:

$doc->addScript(JURI::root().'media/com_szakdolgozat/js/jquery.min.1.4.2.js');
$doc->addScript(JURI::root().'media/com_szakdolgozat/js/typeahead.bundle.js');
$doc->addScript(JURI::root().'media/com_szakdolgozat/js/jquery-ui.min.1.8.1.js');

There is a problem with jquery 1.8.1, because I get error under Joomla 3.2:

Uncaught ReferenceError: jQuery is not defined --> jquery-ui.min.1.8.1.js:10

Which version shall be right for me?

È stato utile?

Soluzione

Joomla 3.x comes packed with jQuery by default, therefore you do not need to import your own copy of it. The following code will import it in noConflict mode if it doesn't already detect it:

JHtml::_('jquery.framework');

I think the issue you're having mentioned in your question is that you have 2 instances of jQuery being loaded and therefore it causes conflicts.

Joomla 3.x also has jQueryUI packed with it. So your final code will look like this:

JHtml::_('jquery.framework');
JHtml::_('jquery.ui');
JHtml::_('script', 'media/com_szakdolgozat/js/typeahead.bundle.js');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top