Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

(solved) Autocomplete TextFields: How can you get it to work?

Go to End

21 Posts   6716 Views


Forum Moderator, 1391 Posts

19 March 2011 at 1:57am

OK, so... Get the tesmodule from here.

It contains the .php and the .js file, a testpagetype called 'AutoCompleteExample.php and a README. The example page creates a very simple form, that should suggest the Titles from your SiteTree_Live table (like 'Contact', probably).

Do the following:
- clean install
- upload the balbusautocompletefield directory to the root of your website
- do a /dev/build/?flush=1.
- login to your admin (or reload if already logged in)
- create an Auto Complet Example page and save
- switch to the frontend


Community Member, 36 Posts

20 March 2011 at 1:42am

Huzzah! It works! :D

I followed these exact steps (for those following this thread)
-Dropped the balbusautocomplete folder into silverstripes root
-Dev build
-Made the page 'AutoComplete Example' in the CMS and set its url to '/autocompleteexample'
-in the mysite _config file added 'Director::addRules(100, array('autocompleteexample' => 'AutoCompleteExample_Controller'));'
-navigated to '[root]/autocompleteexample' in the browser
-type in 'au' into the field (has to be more than 1 character to trigger the jquery apparently)

Gave me 'AutoComplete Example' as a result. This was all on a brand new install of silverstripe the webserver I'm running on my desktop at home. Next I'll repeat this process on the server at work and see how it goes.


Forum Moderator, 1391 Posts

20 March 2011 at 3:16am

Edited: 20/03/2011 3:18am

that's great :-) As for the nr of characters you have tot type: the javascript file has a setting minLength: 2 that determines after how many characters the autocomplete function kicks in... You can change that if you want to.

In some cases you might also want to limit the amount of database/php calls made on the server. If made an attempt at adding some client-side caching yesterday, it works althouhg it's still somewhat primitive. It's not in the download but I put an example on the site.


Community Member, 36 Posts

21 March 2011 at 10:35am

Edited: 21/03/2011 12:18pm

Okay, on the server at work I made another fresh install and repeated the process. The example form from within the balbusautocompletefolder works. On the non-test build where my module is installed I just got a blank page instead. probably because that build is very much reliant on SS templates

If I move the AutocompleteExample.php anywhere else (such as mysite) it still works so the module is being found and recognized across the whole website.

So I made a new module that had a single SS template and a single controller with a copy of the example code in it...didn't work.

In the output of the SS template, the jQuery is completely absent. And it crashes when I try to force it into the SS

I commented out the index() function in the controller so that the controller wouldn't use an SS template...viola! Works just fine!

So thats the problem, the autocompleteform wont work if the form is included within an SS template because the scripts are not being inserted automatically in the SS.

I suppose the question now becomes. "How do I make an SS template use the jquery I give it?"


*facepalm* I forgot to flush the goddamn cache

Nevermind, its working now. Now its time to test this on my module.


Great, it won't work on my module. I just get a spinning indicator and that's it. I noticed that the request for jquery-ui.min.js from Google returns a 407 error. I'm going to modify the code so it looks for a local copy.

Aside from that I am sure one of the other jquery files on the module is causing interference. I'll report any jquery files i find that could be causing problems


Community Member, 36 Posts

21 March 2011 at 3:43pm

Edited: 21/03/2011 4:19pm

That last problem was just a temporary glitch on the proxy server. It looks like the autocomplete field it is able to run on my module without any problems now. Just need to watch out for any interfering jquery files (my module is cluttered with older jquery versions as old as 1.5 and some were getting in the way, taking care of that is simple though).

So to recap, to get autocomplete working:

-Download BalbusAutoComplete
-Install the balbusautocomplete folder in your site root
-Instantiate a new BalbusAutocompleteField([name], [title]) and add it to your fieldset
-define a database table to look up with [object]->setSourceClass([table])
-define a table field to look up with [object]->setSourceField([field]);

All done now, thank you for all your help martimiz

Go to Top