Buy Now
Sign in

How to connect select2 dropdown to remote data sourse

tempus , August 11 at 08:01
T
tempus
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?
GreyHead
Hi tempus,
Please check this FAQ
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much