I am trying to format the output of my data with the autocomplete function from jQuery. So far, I've been able to build the entire process, however, I want to limit the information I show in the autocomplete, but I still want the autocomplete to search through the entire string to find possible matches.
I understand that the formatItem function used in conjunction with the autocomplete from jQuery can accomplish this.
To give you some background here is the entire sequence of my code:
Expand|Select|Wrap|Line Numbers
- $sql = ( 'SELECT cr, title, author, content, id FROM da_labels' );
- $result = mysql_query( $sql );
- $Response = array();
- while( $row = mysql_fetch_object( $result ) ){
- $Response[] = array(
- "id" => $row->id,
- "name" => $row->cr . ": " . $row->title . ": " . $row->content,
- );
- }
Expand|Select|Wrap|Line Numbers
- <script>
- var AllCRData = <?= json_encode ( $Response ); ?>;
- var CRs = [];
- for(var i in AllCRData){
- CRs.push(AllCRData[i].name);
- }
- function getIdFromCR(_name){
- for(var i in AllCRData){
- if(_name == AllCRData[i].name){
- return AllCRData[i].id;
- }
- }
- }
- $(document).ready(function(){
- $("#Responses").autocomplete({
- source: CRs,
- select: function(e, ui){
- $("#hidden_cr").val( getIdFromCR($("#Responses").val()) );
- }});
- });
- </script>
I would like to format my autocomplete, so that it only shows $row->cr and $row->title from the php above, while hiding the $row->content, yet, still searching through the 'content' in order to find the most appropriate option.
I would really appreciate your assistance on how to implement the formatItem function for the autocomplete for jQuery.
Thanks!