XulPlanet Forum

The place to talk about XUL

 FAQ   Search   Memberlist   Usergroups   Register 
 Profile   Log in to check your private messages   Log in 

Autocomplete example: please

 
       XulPlanet Forum Index -> XUL
View previous topic :: View next topic  
Author Message
Djiest



Joined: 20 Sep 2005
Posts: 5

Posted: Tue Sep 20, 2005 8:01 pm    Post subject: Autocomplete example: please

Hi,
can anyone please post an example how to use the textbox autocomplete functionality, using the form-history

Can't seem to find any examples on the web
Back to top
Enn
Site Admin


Joined: 14 Dec 2004
Posts: 431

Posted: Wed Sep 21, 2005 2:20 am    Post subject:

Code:

<textbox id="sometextbox" type="autocomplete"
         autocompletesearch="form-history"
         autocompletesearchparam="some-unique-key-name"
         ontextentered="accepttext();"/>

function accepttext()
{
  var value = document.getElementById("sometextbox").value;

  var fhistory = Components.classes["@mozilla.org/satchel/form-history;1"].
                   getService(Components.interfaces.nsIFormHistory);
  fhistory.addEntry("some-unique-key-name", value);
}


Naturally, you should replace "some-unique-key-name" with something unique for each independent field.
Back to top
epoupaert



Joined: 12 Aug 2005
Posts: 9

Posted: Wed Sep 21, 2005 1:50 pm    Post subject:

I have a similar problem with autocompletesearch="history". I try to add entries to the history using this code:

Code:
var hist = Components.classes["@mozilla.org/browser/global-history;1"].
    getService(Components.interfaces.nsIGlobalHistory);
hist.addPage(src);


This call doesn't generate any exception but does not seem to have any impact on the list provided by the autocomplete. What is wrong with this code?
Back to top
epoupaert



Joined: 12 Aug 2005
Posts: 9

Posted: Wed Sep 21, 2005 4:11 pm    Post subject:

I found a solution to my problem. The following method works:

Code:
function addEntryToHistory (href)
{
   var gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
       .getService(Components.interfaces.nsIBrowserHistory);
   var gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
       .getService(Components.interfaces.nsIURIFixup);
   var fixedUpURI = gURIFixup.createFixupURI(href, 0);
   gGlobalHistory.addURI(fixedUpURI, false, true);
   gGlobalHistory.markPageAsTyped(fixedUpURI);
}
Back to top
Djiest



Joined: 20 Sep 2005
Posts: 5

Posted: Wed Sep 21, 2005 6:27 pm    Post subject: Thanx

Hi,

thank you for helping me out
Back to top
choghok



Joined: 03 Oct 2005
Posts: 3

Posted: Tue Oct 04, 2005 7:24 pm    Post subject:

Looking at the Xulplanet References part it says that nsIFormHistory is not working in new versions of Firefox, is there any new way of fixing autocompletion of textboxes?

thanx in advance!
Back to top
Enn
Site Admin


Joined: 14 Dec 2004
Posts: 431

Posted: Tue Oct 04, 2005 7:31 pm    Post subject:

That's a bug in the xpcom reference. Those interfaces are in fact valid for Firefox.
Back to top
choghok



Joined: 03 Oct 2005
Posts: 3

Posted: Sun Oct 09, 2005 5:37 pm    Post subject: Then How come it does not work?

I have tried to run the code you put here but it does not work. I just did a copy paste, but the javascript just does not want to work. When I remove the accepttext the javascript works again.

/Keyhan
Back to top
choghok



Joined: 03 Oct 2005
Posts: 3

Posted: Mon Oct 10, 2005 3:01 pm    Post subject: Fixed and working!

OK, my fault!

I had a bug in my code. It works like a charm now. Thanx for your help!
Back to top
Display posts from previous:   
       XulPlanet Forum Index -> XUL All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 1999-2006 XULPlanet.com