Forums

Autocompleter from database but also adding something new

Gatsman 21 Oct, 2015
Hello,
i mannaged to create a input field that will suggest values taken from database but in my case i also need for the user to be able to add its own new values or edit the one selected by adding something.

In the image example, i will have only the "LOBIVON" (once) entry in the database and the user will have to add the "PLUS" or "5" or "whatever".
Also the user should be able to write a new value for the field no matter if its found or not in the database.
I cant do that even in the demo-autocompleter form.

Is this possible to edit or add new values with autocompleter or should i use a different method?

P.S. in the image example 02. the loading never stops if its not found so that cant be good...

Thanks for any help.
- John
GreyHead 21 Oct, 2015
Hi John,

I haven't used the Autocompleter for a while but I think that the user should be able to type in a freeform value. That's not true with a drop-down.

That said an optional mask might help here but I can't work out exactly what you need to do :-(

Bob
Gatsman 22 Oct, 2015
Hi Bob,
I also think that the user should be able to type in a freeform value but i dont think this is the case with Autocompleter.
I can't even make it work that way with the demo-form.

Dont know where to start with the optional mask so i might try the jQuerry Autocomplete, i think i saw a thread here about it.

Thanks for your time Bob
- John
Gatsman 23 Oct, 2015
Hi again,
I tried with the jquerry autocomplete but i am stuck...

i use a Custom Code to load the database:
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "SELECT `select_test` FROM `select_test_table` ORDER BY `select_test` ASC";
$db->setQuery($query);
$results = $db->loadColumn();

foreach($results as $result){
	$itemslist .= $prefix . '"' . $result . '"';
    $prefix = ', ';
}
echo $itemslist;
?>

The echo will give me this:
"alpha", "beta", "delta", "epsilon", "gama"


And a Load Javasript that has this code:
$(function() {
	var availableTags = [<?php echo $itemslist ?>];
 $( ".farmako_name" ).autocomplete({
 source: availableTags
 });
});


I can't make it work with the php variable in the load javascript.
If i set the javascipt variable like this
var availableTags = ["alpha", "beta", "delta", "epsilon", "gama"];

It works, but it doesn't if a set it with a php variable.
Can anyone see what am i doing wrong?

I also tried with a DB Read and had no luck.

DB Read Setup and Debugger info in the images.
This topic is locked and no more replies can be posted.