Skip to content

Teguh Eko Budiarto

Web Programming and Sharing Experience

Archive

Category: Javascript

This tip is for windows XP user ( some other windows version will also have similar procedure).

If you are using an automatic configuration script for your internet setting, most probably, Python will not be able to connect to internet. This is troublesome if you want to install some packages which has dependencies which need to be fetched from the net. You need to change your internet options setting to use the proxy address directly.

Below is how to do that:

  • Go to Control Panel
  • Open Internet Options
  • Open Connection Tab
  • Click on LAN Settings button
  • Check the Use a proxy server for your LAN…
  • Enter the proxy IP Address and its port. If you do not know where it is, ask your network administrator or just open the configuration script to find out where is the IP you need to use.
  • Press OK until all the setting windows are closed.

Below is the screen shot of the internet options screen.

Windows XP Professional Internet Options Screen

Windows XP Professional Internet Options Screen

I was using JQuery autocomplete from Jörn Zaefferer to finish a small project for Computer Telephony – IPX PBX user interface. I think this is an awesome plugin ad it is suited very well for my project.

For the project, I need the autocomplete to be able to search all data containing words which begins with the text being typed in the input textbox. However, after browsing through the documentation and try the possible combination of matchContains and matchSubset options of the plugin, it seems that it was not able to do what I want it to do. So, I decided to debug the javascript and go into the code to modify the search algorithm.

When I look into the code, I found this part of code:

function matchSubset(s, sub) {
		if (!options.matchCase)
			s = s.toLowerCase();
		var i = s.indexOf(sub);
		if (options.matchContains == "word"){
			i = s.toLowerCase().search("\\b" + sub.toLowerCase());
		}
		if (i == -1) return false;
		return i == 0 || options.matchContains;
	};

In the fifth line of the function, there is a value check for matchContains option which implies that it received “word” value besides boolean true or false. The code uses the javascript search function with regex using \b tag which means word boundary. This means that it already have the functionality to search for subset contained in each word of the search data.
I immediately changed my code to try to use the option by adding this line:

matchContains:"word"

So, the whole code to activate the autocomplete textbox is as below:

 $("#searchInput").autocomplete(json.Data, {
                    cacheLength:1,
                    delay:0,
                    formatItem: function(row)
                    {
                        var sShow = row.Name + " - (" + row.TypePhone + ") " + row.Phone;
                        return sShow;
                    },
                    matchContains:"word",
                    matchSubset:true,
                    max:100,
                    minChars:1,
                    width:285,
                    selectFirst:true,
                    scrollHeight:"100px"
                });

After that, I try to find in the author’s website and JQuery documentation where in the world that option is being documented. At last I found it in the change log for the latest version 1.1 (per this post date). It should be also written in the JQuery plugin documentation, since it is a very useful feature, at least for me at the time :) . I hope the author would update the documentation accordingly soon.