|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionMost auto-complete textboxes may have a reverse effect on end-users. Instead of helping them get things done faster, they get irritated by design flaws made by the programmer. (Admittedly, I've made such design flaws too.) I got to learn this lesson when designing my first auto-complete edit control, found here[^]. Although it seemingly looks intuitive, I forgot to consider the fact that what if the end-user wanted to type just 'ap' but the 'ple' appears out of nowhere? This means that the end-user would then have to hunt for, and press the delete key. After seeing how GMail made its auto-complete, I took the idea and implemented my own version of the auto-complete control. Auto-complete textbox control:
How does it work?The important event that will fire whenever the user press any key is Using the JavaScript The user can also select the options using the mouse. This is done through three events: How do you implement it into your own textbox?Firstly, include the .js file into your script: <script language="javascript" type="text/javascript"
src="actb.js"></script>
Next, create an array (in JavaScript) containing the keywords: customarray = new Array('apple','pear','mango','pineapple',
'orange','banana','durian', 'jackfruit','etc');
Apply the widget to your textbox using JavaScript: actb(document.getElementById('textbox_id'),customarray);
And you're done! TweakabilityThis auto-complete edit control has some customizable features: /* ---- Variables ---- */
// Autocomplete Timeout in ms (-1: autocomplete never time out)
this.actb_timeOut = -1;
// Number of elements autocomplete can show (-1: no limit)
this.actb_lim = 4;
// should the auto complete be limited to the beginning of keyword?
this.actb_firstText = false;
// Enable Mouse Support
this.actb_mouse = true;
// Delimiter for multiple autocomplete.
// Set it to empty array for single autocomplete
this.actb_delimiter = new Array(' ',',');
// Show widget only after this number of characters is typed in.
this.actb_startcheck = 1;
/* ---- Variables ---- */
/* --- Styles --- */
this.actb_bgColor = '#888888';
this.actb_textColor = '#FFFFFF';
this.actb_hColor = '#000000';
this.actb_fFamily = 'Verdana';
this.actb_fSize = '11px';
this.actb_hStyle = 'text-decoration:underline;font-weight="bold"';
/* --- Styles --- */
this.actb_keywords = new Array();
The styles are pretty self-explanatory; tweak the values for best results for your own website. Firstly, the variable Next, the variable Thirdly, the Also, the The Lastly, ImplementationsAs of version 1.3, all of the above mentioned are public variables. This can be useful in emulating controls like Google Suggest. When you apply the control to your textbox using the Changing the autocomplete list obj = actb(document.getElementById('textbox_id'),customarray);
// ... after some time ...
obj.actb_keyword = new Array('this','is','a','new','set','of','keywords');
Multiple auto-complete textboxes obj = new actb(document.getElementById('textbox_id'),customarray);
obj2 = new actb(document.getElementById('textbox2_id'),customarray2);
Multiple textboxes (different options) obj = new actb(document.getElementById('textbox_id'),customarray);
obj.actb_mouse = false; // no mouse support
obj2 = new actb(document.getElementById('textbox2_id'),customarray2);
obj2.actb_startcheck = 2; // start actb only after 2nd character
Todo
Tested browsers
Finally...Thank you to all of you who have supported, modified, and offered your suggestions to the control! I'm extremely apologetic for the inactiveness of this project because of schoolwork etc. However, I still try my best to work on it whenever anyone has a new feature request! LicenseThis control will be, from effect of version 1.1, published under Creative Common License [^] Change Log
| ||||||||||||||||||||||||||||