Changed at 27 December 07 / 16:36
I just created a new function, based on the 'autocomplete'-function.
'AutoCompleteAfter' can be used to complete an emailaddress for example.
You tell the script after wich character the input has to be auto completed.
When I type: robgeerts@h, the script explodes on @ and checks wich provider match the 'h', in this case, the script wil complete the input with 'otmail.com'
// check if the field exists and is a textfield
if( !$this->fieldExists($field) || strtolower(get_class( $this->_fields[$field][1] )) != 'textfield')
{
trigger_error(
'You have to declare the textfield first! '.
'The field "'.$field.'" does not exists in the form!',
E_USER_WARNING
);
return;
}
// check if the options are correct
if( !is_array( $options ) )
{
trigger_error( 'You have to give an array as options!', E_USER_WARNING );
return;
}
// add the javascript file if not done yet
if( !$setJS )
{
$setJS = true;
$this->_setJS( FH_FHTML_DIR.'js/autocomplete.js', true );
}
// add the javascript to the fields "extra" argument
$this->_fields[$field][1]->_sExtra .= " onkeypress='return autocompleteafter(this, event,\"".$after."\", ".$field."_values);' ";
}
?>
AND
add the following function to js/autocomplete.js:
function autocompleteafter(oTextbox, oEvent, After, arrValues) {
switch (oEvent.keyCode) {
case 38: //up arrow
case 40: //down arrow
case 37: //left arrow
case 39: //right arrow
case 33: //page up
case 34: //page down
case 36: //home
case 35: //end
case 13: //enter
case 9: //tab
case 27: //esc
case 16: //shift
case 17: //ctrl
case 18: //alt
case 20: //caps lock
case 8: //backspace
case 46: //delete
return true;
break;
default:
textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode));
var iLen = oTextbox.value.length;
var my_string = oTextbox.value;
var my_array = my_string.split(After);
var sMatch = autocompleteMatch(my_array[1], arrValues);
if (sMatch != null) {
oTextbox.value=my_array[0] + After + sMatch;
textboxSelect(oTextbox, iLen, oTextbox.value.length);
}
return false;
}
}
AND DONT FORGET:
to replace the function 'autocompleteMatch' (in autocomplete.js) with the function below:
function autocompleteMatch (sText, arrValues) {
if(sText!=null){
for (var i=0; i < arrValues.length; i++) {
if (arrValues[i].toLowerCase().indexOf(sText.toLowerCase()) == 0) {
return arrValues[i];
}
}
}