AJAX autocompletion field - multiple inputs hack

The AJAX auto-Complete Text Field is great, however it only allows one entry to be entered at a time. When a new value is selected from the suggestion list, the text field is cleared automatically.

What I needed to do was like the "Send To" field in gmail, in which you can enter multiple entries in a text field, separated with commas or whatever.

This could be done by editing the javascript file that came with the download. The steps are as follows:

1. Open the \Creator2\nb4.1\samples\complib\ui.complib file with Winzip.

2. Extract the ui.jar file

3. Extract the META-INF\autocomplete\script.js file from ui.jar.

4. Look for "bpui.autocomplete.chooseItem = function(targetName, item)" and change it to the following:

bpui.autocomplete.chooseItem = function(targetName, item) {

if (!bpui.autocomplete.state.onchoose) {

var target = document.getElementById(targetName);

var targetValue = target.value;

if (targetValue.indexOf(',') != -1){

// comma found in original content, append selected item to the end

target.value = target.value + item;

}else{

// if field is empty or there're no commas, replace the original content

target.value = item;

}

target.focus();

} else {

bpui.autocomplete.state.onchoose(item);

}

}

5. Then reverse the steps and put the updated jar files back into ui.complib.

6. Delete previously imported AJAX comp libraries from the Component Library Manager and repeat the steps in http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/aja ximportcomponents.html. Make sure you point to the updated ui.complib file.

You could basically change the behaviour of any of the included AJAX components this way. It's just editing of javascript.

[1845 byte] By [himurakenshin] at [2007-11-26 6:40:12]
# 1
Hi,Thank you very much for the example. RK
RunaK at 2007-7-6 14:52:56 > top of Java-index,Development Tools,Java Tools...
# 2

I tried following the similar steps you described on Studio Creator 2. The path to ajax-components-0.96.complib was different and the path to the script file in the ajax-components.jar file was different. However once I recreate the zip file and change the extenstion back to complib, Studio Creator returns me "Unable to read the component library file specified" when i try to import the file into the componet library manager.

The directory structure of the compressed comlib file with winzip is same as the original directory structure.

cyberalex30 at 2007-7-6 14:52:56 > top of Java-index,Development Tools,Java Tools...