Welcome Guest, Not a member yet? Register   Sign In
jQuery UI Autocomplete with CI ??
#21

[eluser]seanloving[/eluser]
[quote author="packetfox" date="1276114730"] Any clues what i am doing wrong?
[/quote]

@packetfox- I think your json function is not properly passing 'response' and 'message' to your autocomplete function. Try something like what is shown above:

Code:
$o['response'] = true;
$o['message'] = array();
foreach ($companies as $company){
   $o['message'] = ...

good luck
SL
#22

[eluser]pickupman[/eluser]
You need to change your json array. You need three values for each json entry.
Code:
function json(){
        $companies = $this->M_companies->getCompanies();
        
        $o = array(); //Setup array
        $o['response'] = 'false'; //Default response
        if(count($companies) > 0){

           $o['response'] = 'true'; //We've got rows change default response
           foreach ($companies as $company){
            $o['message'][] = array('value' => $company[company_name],
                         'label' => $company[company_name],
                         'id'    => $company[company_name]);
           }
        }
        echo json_encode($o);
    }
#23

[eluser]lexusgs430[/eluser]
Hey guys, was wondering if you could help me get my autocomplete search working. Im getting mad errors. Ive got it working as far as it looks like its looking stuff up but then in my firebug its just returning all sorts of errors.

Namely:

this.menu is undefined
this._trigger("open")}else this.close(...e:c};return e.extend({label:c.label||

Im thinking the problem is just in my javascript but not sure.

Code:
jq part = following

$().ready( function() {    
        
        $(".search").autocomplete({
            minLength: 5,
            source:
                function(req, add)
                {
                    $.ajax({
                        url: '<?php echo site_url('/search/lookup');?>',
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:    
                            function(data)
                            {
                                if(data.response =='true')
                                {
                                    add(data.message);
                                }
                            }
                    });
                },
            select:
                function(event, ui)
                {
                  $(this).end().val(ui.item.title);
                }
        });    
    });

------ model lookup = following (using the dmz datamapper library)

    function lookup_item($keyword)
    {
        $i = new Item();
        $i->like('itemTitle', $keyword);
        $results = $i->get();
        return $results;
    }

------ controller = following

    function lookup()
        {
            // process posted form data (the requested product)
            $keyword = $this->input->post('search');
            $data['response'] = 'false'; //Set default response
            $i = new Item();
            $query = $i->lookup_item($keyword); //Search DB
            if( ! empty($query) )
            {
                //print_r[$row];
                $data['response'] = 'true'; //Set response
                $data['message'] = array(); //Create array
                foreach( $query as $row )
                {
                    $data['message'][] = array( 'label'=> $row->id,
                                                'item'=> $row->itemTitle,
                                                'value'=> $row->itemTitle); //Add a row to array
                }
            }
            if(IS_AJAX)
            {
                echo json_encode($data); //echo json string if ajax request
            }
            else
            {
                $data['results'] = $query;
                $data['main_content'] = "search-results";
                $this->load->view('includes/template',$data); //Load html view of search results
            }

        }


any help much appreciated!
#24

[eluser]pickupman[/eluser]
Got a live link by chance? Since the syntax errors are not part of your code, it could be another script, or your version of jQuery. 1.8 beta added autocomplete, but I had weird issues with it. I am using 1.8.2 now which fixed some of the errors with item selection. Sometimes if you have a js error with something else, it will break other things as well.

Firebug should be telling what file the error is happening in.
#25

[eluser]lexusgs430[/eluser]
[quote author="pickupman" date="1278119735"]Got a live link by chance? Since the syntax errors are not part of your code, it could be another script, or your version of jQuery. 1.8 beta added autocomplete, but I had weird issues with it. I am using 1.8.2 now which fixed some of the errors with item selection. Sometimes if you have a js error with something else, it will break other things as well.

Firebug should be telling what file the error is happening in.[/quote]

Yea its stylesearcher - Yea I was using 1.8.2, now im trying the 1.9m2 version as I uploaded it to a test folder on my server to see if autocomplete was working and it was, so ive tried couple different versions. But the error is indeed with the ui js file, hmmm.
#26

[eluser]lexusgs430[/eluser]
oh and sometimes instead of the previously mentioned error, it returns this error instead -

e("<ul></ul>").addClass("ui-autocomplete").appendTo("body", d).mousedown(function () {setTimeout(function () {clearTimeout(a.closing);}, 13);}).menu({input: e(), focus: function (c, b) {b = b.item.data("item.autocomplete");false !== a._trigger("focus", null, {item: b}) && /^key/.test(c.originalEvent.type) && a.element.val(b.value);}, select: function (c, b) {b = b.item.data("item.autocomplete");false !== a._trigger("select", c, {item: b}) && a.element.val(b.value);a.close©;c = a.previous;if (a.element[0] !== d.activeElement) {a.element.focus();a.previous = c;}a.selectedItem = b;}, blur: function () {a.menu.element.is(":visible") && a.element.val(a.term);}}) is undefined

when loading the page
#27

[eluser]lexusgs430[/eluser]
well i think I figured out source of problem, a jqui based plugin Im using for a menu. Damnit, I love that menu Sad( - I deactivated it and it was working!
#28

[eluser]pickupman[/eluser]
I like jquery.superfish for menus. It works well, and is easy to implement. Glad you were able to narrow down your problem. 1.8.2 seems to work pretty well 99% of the time, it seems to have issues sometimes between mouse clicks, and someone arrowing down and pressing [enter].
#29

[eluser]goldensona[/eluser]
Hi


this is my jquery ui autocomplete code i cant get the result come back from database it returns error.what wrong in my code please can someone correct my and guide me to solve this error

this Fatal error: Call to a member function num_rows() on a non-object in

view file

Code:
< cript t  ype="text/javascript" src="&lt;?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/jquery-1.4.2.js"?&gt;">[removed]
< cript t  ype="text/javascript" src="&lt;?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.core.js"?&gt;">[removed]
  < cript t  ype="text/javascript" src="&lt;?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.widget.js"?&gt;">[removed]
  < cript t  ype="text/javascript" src="&lt;?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.position.js"?&gt;">[removed]
< cript type="text/javascript" src="&lt;?php echo base_url()."jquery-ui-1.8.4.custom/development-bundle/ui/jquery.ui.autocomplete.js"?&gt;">[removed]


    
[removed]
//Javascript
$("input[name='singlecity']").autocomplete({
        source: function(req, add){
                $.ajax({
                    url: '&lt;?php echo site_url('search');?&gt;',
                    dataType: 'json',
                    type: 'POST',
                    data: req,
                    success: function(data){
                        if(data.response =='true'){
                           add(data.message);
                        }
                    }
                });
        },
        minLength: 3,
        select: function(event, ui){
            $(this).end().val(ui.item.value);
        }
     });
[removed]
&lt;/head&gt;

&lt;body&gt;
&lt;input type="text" name="singlecity"  size="48"&gt;

&lt;/body&gt;



this is my controller file



Code:
class Search extends Controller{
  
function Search(){
// load Controller constructor
parent::Controller();
// load the model we will be using
$this->load->model('searchcity', '', TRUE);
// load the database and connect to MySQL
$this->load->database();
// load the needed helpers
$this->load->helper('url');
}


  function index(){
     $search = $this->input->post('term');
        
        if(!IS_AJAX || empty($search))
            echo "no string";
        
        $data['response'] = 'false';
        
        $query = $this->searchcity->citysearch($search); //Search DB
     if($query->num_rows() > 0)
     {
        $data['response'] = 'true'; //Set response
        $data['message'] = array(); //Create array
        foreach($query->result() as $row)
        {
            $data['message'][] = array('label'=> $row->id, 'value'=> $row->city); //Add a row to array
        }
     }
        if(IS_AJAX)
        {
            echo json_encode($data); //echo json string if ajax request
        }
        else
        {
            $this->load->view('search',$data); //Load html view of search results
        }
  }

}  
?&gt;


this is my model file


Code:
function citysearch($search)
{
   if(empty($part_number)) return FALSE; //nothing to search

   $this->db->like('city', '$search');

   $query = $this->db->get('townandcites');

  
   if($query->num_rows() > 0)

       return $query->result();

  return FALSE;
}




thanks
#30

[eluser]pickupman[/eluser]
I may have given the wrong code through my email.
Code:
function citysearch($search)
{
   if(empty($part_number)) return FALSE; //nothing to search

   $this->db->like('city', $search);

   $query = $this->db->get('townandcites');

  
   if($query->num_rows() > 0)

       return $query->result();

  return FALSE;
}




Theme © iAndrew 2016 - Forum software by © MyBB