<?php ... $ac = new jqAutocomplete($conn); // We use the northwind database // Set the SQL command $ac->SelectCommand = "SELECT CompanyName FROM customers WHERE CompanyName LIKE ? ORDER BY CompanyName"; // Set from where to get the dat. In this case from the same file $ac->setSource("firstautocomplete.php"); // set the minLength option $onfocus = << FOCUS; function (event, ui) { // prevent value inserted on focus return false; } FOCUS; //Set focus event $as->setEvent('focus', $onfocus); // Enjoy $ac->renderAutocomplete("#company"); ?>
As can be seen from this example the first parameter of the method is the name of the event and the second is the code associated with that event. Note how $onfocus is written - function(event, ui) - This will produce in the cleint
focus:function(event, ui) {....}
Below is the list of events that can be used:
Event |
Parameters |
Description |
---|---|---|
search |
event |
Before a request (source-option) is started, after minLength and delay are met. Can be canceled (return false), then no request will be started and no items suggested. |
open |
event |
Triggered when the suggestion menu is opened. |
focus |
event |
Before focus is moved to an item (not selecting), ui.item refers to the focused item. The default action of focus is to replace the text field's value with the value of the focused item, though only if the focus event was triggered by a keyboard interaction. Canceling this event prevents the value from being updated, but does not prevent the menu item from being focused. |
select |
event |
Triggered when an item is selected from the menu; ui.item refers to the selected item. The default action of select is to replace the text field's value with the value of the selected item. Canceling this event prevents the value from being updated, but does not prevent the menu from closing. |
close |
event |
When the list is hidden - doesn't have to occur together with a change. |
change |
event |
After an item was selected; ui.item refers to the selected item. Always triggered after the close event. |