17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2333 Views |
-
AutocompleteTextField

10 March 2007 at 9:27pm
Hi all -- anyone have any idea what the optionsURL protocol is? Examples?
thanks
J -
Re: AutocompleteTextField

12 March 2007 at 4:29pm
The $optionsURL is a relative URL that you use to populate a list of available options when you enter text into the field. The URL should return an unordered list of options. The text inside each list item is used to populate the field when it is selected.
The Ajax.Autocompleter class in the prototype library will make a get request and pass the name of the field as an argument.
For example:
Say we have an AutocompleteTextField:
$field = new AutocompleteTextField('AutoField', 'My autocomplete field label', 'controller/autocompleteaction');
When text is entered into the field, it will make an ajax request behind the scenes to 'controller/autocompleteaction'.
On your controller for the URL you have given, define the function 'autocompleteaction'. This will be called and the name of the field will be available in the $_REQUEST array:
function autocompleteaction() {
// find possible matches for the field
$SQL_prefix = Convert::raw2sql($_REQUEST['AutoField']);
$matches = DataObject::get('MyClass', "`MyClass`.`FieldToSearch` LIKE '{$SQL_prefix}%'");$output = '<ul>';
if($matches) foreach($matches as $match)
$output .= '<li>' . $match->UseToPopulateField . '</li>';$output .= '</ul>';
return $output;
}
| 2333 Views | ||
|
Page:
1
|
Go to Top |

