CAutoComplete
CAutoComplete generates an auto-complete text field.
CAutoComplete is based on the
jQuery Autocomplete.
Public Properties
Hide inherited properties
| Property | Type | Description | Defined By |
| actionPrefix |
string |
the prefix to the IDs of the actions. |
CWidget |
| attribute |
string |
the attribute associated with this widget. |
CInputWidget |
| autoFill |
boolean |
fill the textinput while still selecting a value, replacing the value
if more is typed or something else is selected. |
CAutoComplete |
| cacheLength |
integer |
the number of backend query results to store in cache. |
CAutoComplete |
| controller |
CController |
the controller that this widget belongs to. |
CWidget |
| cssFile |
mixed |
the CSS file used for the widget. |
CAutoComplete |
| data |
array |
data that would be saved as client-side data to provide candidate selections. |
CAutoComplete |
| delay |
integer |
the delay in milliseconds the autocompleter waits after
a keystroke to activate itself. |
CAutoComplete |
| formatItem |
string |
a javascript function that provides advanced markup for an item. |
CAutoComplete |
| formatMatch |
string |
a javascript function that can be used to limit the data that autocomplete
searches for matches. |
CAutoComplete |
| formatResult |
string |
a javascript function that provides the formatting for the value to be
put into the input field. |
CAutoComplete |
| highlight |
boolean|string |
Whether and how to highlight matches in the select box. |
CAutoComplete |
| htmlOptions |
array |
additional HTML options to be rendered in the input tag |
CInputWidget |
| id |
string |
id of the widget. |
CWidget |
| inputClass |
string |
the CSS class for the input element. |
CAutoComplete |
| loadingClass |
string |
the CSS class used when the data is being loaded from backend. |
CAutoComplete |
| matchCase |
boolean |
whether or not the comparison is case sensitive. |
CAutoComplete |
| matchContains |
boolean |
whether or not the comparison looks inside
(i. |
CAutoComplete |
| matchSubset |
boolean |
whether or not the autocompleter can use a cache for more
specific queries. |
CAutoComplete |
| max |
integer |
limit the number of items in the select box. |
CAutoComplete |
| methodChain |
string |
the chain of method calls that would be appended at the end of the autocomplete constructor. |
CAutoComplete |
| minChars |
integer |
the minimum number of characters a user has to type before
the autocompleter activates. |
CAutoComplete |
| model |
CModel |
the data model associated with this widget. |
CInputWidget |
| multiple |
boolean |
whether to allow more than one autocompleted-value to enter. |
CAutoComplete |
| multipleSeparator |
string |
seperator to put between values when using multiple option. |
CAutoComplete |
| mustMatch |
boolean |
if set to true, the autocompleter will only allow results that
are presented by the backend. |
CAutoComplete |
| name |
string |
the input name. |
CInputWidget |
| options |
array |
additional options that can be passed to the constructor of the autocomplete js object. |
CAutoComplete |
| owner |
CBaseController |
owner/creator of this widget. |
CWidget |
| resultsClass |
string |
the CSS class for the dropdown list. |
CAutoComplete |
| scroll |
boolean |
whether to scroll when more results than configured via scrollHeight are available. |
CAutoComplete |
| scrollHeight |
integer |
height of scrolled autocomplete control in pixels. |
CAutoComplete |
| selectFirst |
boolean |
if this is set to true, the first autocomplete value will
be automatically selected on tab/return, even if it has not been handpicked
by keyboard or mouse action. |
CAutoComplete |
| skin |
mixed |
the name of the skin to be used by this widget. |
CWidget |
| textArea |
boolean |
whether to show the autocomplete using a text area. |
CAutoComplete |
| url |
string|array |
the URL that can return the candidate selections. |
CAutoComplete |
| value |
string |
the input value |
CInputWidget |
| viewPath |
string |
Returns the directory containing the view files for this widget. |
CWidget |
| width |
integer |
specify a custom width for the select box. |
CAutoComplete |
Property Details
public boolean $autoFill;
fill the textinput while still selecting a value, replacing the value
if more is typed or something else is selected. Defaults to false.
public integer $cacheLength;
the number of backend query results to store in cache.
If set to 1 (the current result), no caching will happen. Must be >= 1. Defaults to 10.
the javascript options
public mixed $cssFile;
the CSS file used for the widget. Defaults to null, meaning
using the default CSS file included together with the widget.
If false, no CSS file will be used. Otherwise, the specified CSS file
will be included when using this widget.
public array $data;
data that would be saved as client-side data to provide candidate selections.
Each array element can be string or an associative array.
The url property will be ignored if this property is set.
public integer $delay;
the delay in milliseconds the autocompleter waits after
a keystroke to activate itself. Defaults to 400.
public array $extraParams;
extra parameters for the backend. If you were to specify
array('bar'=>4), the autocompleter would call the backend with a GET
parameter 'bar' 4. The param can be a function that is called to calculate
the param before each request.
public string $formatItem;
a javascript function that provides advanced markup for an item.
For each row of results, this function will be called. The returned value will
be displayed inside an LI element in the results list. Autocompleter will
provide 4 parameters: the results row, the position of the row in the list of
results (starting at 1), the number of items in the list of results and the search term.
The default behavior assumes that a single row contains a single value.
public string $formatMatch;
a javascript function that can be used to limit the data that autocomplete
searches for matches. For example, there may be items you want displayed to the user,
but don't want included in the data that's searched. The function is called with the same arguments
as formatItem. Defaults to formatItem.
public string $formatResult;
a javascript function that provides the formatting for the value to be
put into the input field. Again three arguments: Data, position (starting with one) and
total number of data. The default behavior assumes either plain data to use as result
or uses the same value as provided by formatItem.
public boolean|string $highlight;
Whether and how to highlight matches in the select box.
Set to false to disable. Set to a javascript function to customize.
The function gets the value as the first argument and the search term as the
second and must return the formatted value. Defaults to Wraps the search term in a <strong> element.
public string $inputClass;
the CSS class for the input element. Defaults to "ac_input".
public string $loadingClass;
the CSS class used when the data is being loaded from backend. Defaults to "ac_loading".
public boolean $matchCase;
whether or not the comparison is case sensitive. Important
only if you use caching. Defaults to false.
public boolean $matchContains;
whether or not the comparison looks inside
(i.e. does "ba" match "foo bar") the search results. Important only if
you use caching. Don't mix with autofill. Defaults to false.
public boolean $matchSubset;
whether or not the autocompleter can use a cache for more
specific queries. This means that all matches of "foot" are a subset
of all matches for "foo". Usually this is true, and using this options
decreases server load and increases performance. Only useful with
cacheLength settings bigger than one, like 10. Defaults to true.
public integer $max;
limit the number of items in the select box. Is also sent as
a "limit" parameter with a remote request. Defaults to 10.
public string $methodChain;
the chain of method calls that would be appended at the end of the autocomplete constructor.
For example, ".result(function(...){})" would cause the specified js function to execute
when the user selects an option.
public integer $minChars;
the minimum number of characters a user has to type before
the autocompleter activates. Defaults to 1.
public boolean $multiple;
whether to allow more than one autocompleted-value to enter. Defaults to false.
public string $multipleSeparator;
seperator to put between values when using multiple option. Defaults to ", ".
public boolean $mustMatch;
if set to true, the autocompleter will only allow results that
are presented by the backend. Note that illegal values result in an empty
input box. Defaults to false.
public array $options;
additional options that can be passed to the constructor of the autocomplete js object.
This allows you to override existing functions of the autocomplete js class (e.g. the parse() function)
If you want to provide JavaScript native code, you have to prefix the string with js: otherwise it will
be enclosed by quotes.
public string $resultsClass;
the CSS class for the dropdown list. Defaults to "ac_results".
public boolean $scroll;
whether to scroll when more results than configured via scrollHeight are available. Defaults to true.
public integer $scrollHeight;
height of scrolled autocomplete control in pixels. Defaults to 180.
public boolean $selectFirst;
if this is set to true, the first autocomplete value will
be automatically selected on tab/return, even if it has not been handpicked
by keyboard or mouse action. If there is a handpicked (highlighted) result,
that result will take precedence. Defaults to true.
public boolean $textArea;
whether to show the autocomplete using a text area. Defaults to false,
meaning a text field is used.
public string|array $url;
the URL that can return the candidate selections.
A 'q' GET parameter will be sent with the URL which contains what the user has entered so far.
If the URL is given as an array, it is considered as a route to a controller action and will
be used to generate a URL using CController::createUrl;
If the URL is an empty string, the currently requested URL is used.
This property will be ignored if data is set.
public integer $width;
specify a custom width for the select box. Defaults to the width of the input element.
Method Details
|
protected array getClientOptions()
|
| {return} |
array |
the javascript options |
Initializes the widget.
This method registers all needed client scripts and renders
the autocomplete input.
|
public void registerClientScript()
|
Registers the needed CSS and JavaScript.
|
public static void registerCssFile(string $url=NULL)
|
| $url |
string |
the CSS URL. If null, a default CSS URL will be used. |
Registers the needed CSS file.
As a tip for those using this extension, it is good to know that if you specify a url in the properties array (instead of passing in an array of values for the data attribute), the component is expecting a string separated by "\n" as a return value. Not only does your function need to return a string (not array), but you must also echo the string out, not pass it back with a return statement. For example:
Make sure that you use "\n", not '\n'. Also, note that the data will be displayed in the order that it is sent, so sort your return data before hand.