Halnex 0 Newbie Poster

Hello,

I'm trying to implement autocomplete on a single field "contact".
This should query the "contacts" table looking for an id but displaying the firstname in the input field.

This is my function inside ListingsController.php, every listing belongs to a contact and every contact belong to a listing.

public function action_getClientsByLetters() { 
    $term = Input::get('query'); $data = array(); 
    $query = DB::query(" SELECT * FROM contacts WHERE MATCH (contact) AGAINST('+".$term."*' IN BOOLEAN MODE) ");
    foreach ($query as $results => $contact) {
        $data[] = array(
            'id' => $contact->id,
            'value' => $contact->firstname
        );
    }
    return json_encode($data);
}

This is the form field in add.blade.php (adding listing)

<p>{{ Form::text('contact_id', '', array('class'=>'form-control', 'id'=>'contact')) }}</p>

And this is the JS

<script> 
    $("#contact").autocomplete({ 
        source: "getClientsByLetters", 
        minLength: 2, 
        select: function( event, ui ) {
          }
    });
</script>

However, when I start typing my name, nothing loads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.