Forums

How to connect select2 dropdown to remote data sourse

tempus 11 Aug, 2018
Hi Greyhead

Please advise me on how to make it work

In form I have dynamic dropdown and the next Custom code on load
<?php
$doc = JFactory::getDocument();
JHtml::_('jquery.framework');
$doc->addStylesheet(JUri::root().'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css');
$doc->addScript(JUri::root().'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js');

$script = "
jQuery(document).ready(function(jQ) {
jQ('#dropdown2').select2({
ajax: {
url: 'https://my.site.org/index.php?option=com_chronoforms5&chronoform=123&tmpl=component&tvout=ajax',
dataType: 'json'
}
});
});
";
$doc->addScriptDeclaration($script);
?>
URL in the code above has a valid json output

How to put this retrieved options to the dropdown?
This topic is locked and no more replies can be posted.