Skip to content

Teguh Eko Budiarto

Web Programming and Sharing Experience

Archive

Archive for September, 2009

I just upgraded my laptop harddisk. It is not that I need more space, but the old harddisk was failed several times, in a very critical moment when having tele-screen-sharing-conference with my client :( . Anyway, that was a different story. The story here is that I have to re-install my computer, and unfortunately, I haven’t got image backup of my HDD yet…another big mistake. However, I managed in a single, almost sleepless night to make it ready for to code again, and now already create the image for clean backup :) .

One of the main application I used to code is Netbeans. I love this editor. However, I am using Japanese as my windows locale, so as default, Netbeans will use that setting and display japanese menu. Even though until now, I am already living in Japan for 5 years, I still prefer English as my application menu language, so I don’t have to bother searching difficult kanji which can waste my productive time.

I did the setting before to change the locale to English after some time searching the web for the correct setting. And now, I have to do it again, but I don’t know where to find it anymore since I did not write about it anywhere. So, here it is. You may change the configuration of Netbeans, following instructions from this Netbeans Wiki.

To change the locale, you need to add text below after the last configuration in netbeans_default_options.

-J-Duser.language=en -J-Duser.region=US -J-Dfile.encoding=UTF-8

This is valid for Netbeans 6.5, and 6.71 when this post is written. I hope this can be useful for somebody besides me :) .

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:

1
2
3
4
5
6
7
8
9
10
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 $("#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.