1
zyspec
jQueryUI autocomplete local data source problem
  • 2011/2/9 15:19

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


I'm trying to implement jQueryUI autocomplete widget using a local datasource and I can't figure out what value I'm suppose to use for the 'source:' attribute.

If I reference a var then it works fine but if I reference a file (say suggest.php) then the code inside suggest.php is never executed. It appears that jqueryUI autocomplete is looking at a specific location (directory) but I can't figure out where to locate the suggest.php file.

The code inside suggest.php works fine if I call it directly
http://mysite/modules/mymodule/suggest.php?term=search_value

I've tried locating the suggest.php file in the module directory, the main Xoops directory, the /Frameworks/jquery directory, the theme directory...

The javascript 'snippet' looks like this:

$( "#termbox" ).autocomplete({
    
source"suggest.php",
             
minLength3,
       });
"


Ideas?

2
kerkyra
Re: jQueryUI autocomplete local data source problem
  • 2011/2/9 16:51

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


try
Quote:

$( "#termbox" ).autocomplete({
source: "<{$xoops_url}>/modules/yourmodule/path_to_file/suggest.php",
minLength: 3
});"


also if minLength is your last option you dont need the comma ',' at the end of the line

3
zyspec
Re: jQueryUI autocomplete local data source problem
  • 2011/2/9 18:05

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Thanks for the suggestion kerkyra, but it didn't make any difference.

According to the jQueryUI Autocomplete it should work with a 'relative' file name, not a URL. I also tried using XOOPS_ROOT_PATH instead of $xoops_url, no difference.

I've seen plenty of examples where this works outside of XOOPS but I can't seem to find the magic file location necessary inside of XOOPS.

Maybe I have to treat the file like it's a remote JSON source and use a $.ajax callback function instead...

4
kerkyra
Re: jQueryUI autocomplete local data source problem
  • 2011/2/14 16:55

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


the url not being relative should work fine since it is in the same domain that you are making the ajax call. (i know because i do the same thing) :)

BUT you should indeed return your data as json.

json_encode() on your array and echo it at the end of your function. DO NOT return it.

the array should have at least the following structure
Quote:

$vals[] = array(
"id"=>your data id,
"label"=>your data label (what the drop down will show),
"value"=>the value that will assign in your input field, this could be the same as your label for example
);

apart from that you can add anything alse into the array but autocomplete NEEDS those values.
whttp://www.guidemap.gr - Beta is out...

5
zyspec
Re: jQueryUI autocomplete local data source problem
  • 2011/2/14 21:54

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Thanks kerkyra,

I was able to get it to work using something similar to this:

<script>
$(function() {
$( 
"#termbox" ).autocomplete({
    
source: function( requestresponse ) {
        $.
getJSON("myURL",
            { 
term: $("#termbox").val(),
              
categoryID: $("#categoryID").val(),
              
pos: $("#pos").val(),
              
type: $("#type").val()
            },
            function(
data) {
                
response(data);
            });
        },
        
minLength5
    
});
});
script>

6
kerkyra
Re: jQueryUI autocomplete local data source problem
  • 2011/2/15 15:57

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


if it works for you its all good :)
whttp://www.guidemap.gr - Beta is out...

Login

Who's Online

144 user(s) are online (54 user(s) are browsing Support Forums)


Members: 0


Guests: 144


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits