Forums

autocompleter with db read

tobajarrat1 28 Sep, 2016
Hi @ all!

I try to get a autocompleter field with values from database to work (for country selection), but it doesn't work and i have no idea why.
Maybe someone can help me to get this solved. My setup is as followed:

____on load:
->Autocompleter
-fields selector: #country
-field name: tag
-AJAX form event: autocomplete

____on autocomplete:
->DB read
-Table name: country (table exists)
-multiread: yes
-Enable Model ID: yes
-Model ID: data
-fields: en (country names in english)
-order: en

I also have other fields in the database with country names in other languages. Is it possible to detect the user language and change the field regarding to the language?

Hopefully anybody can help me, im sitting here for 3 days.

Thank you!
GreyHead 03 Oct, 2016
Hi tobajarrat1,

There is an example here tha shows the code you need to use to package the data to be returned to the form.

You can detect the current languate with a custom code action using code like this:
<?php
$jlang = \JFactory::get Language();
$form->data['lang'] = $jlang->tag();
?>
This should give you a value like en-GB in the $form->data['lang'] variable.

Bob
This topic is locked and no more replies can be posted.