• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
jQuery UI Autocomplete with CI ??

#41
[eluser]goldensona[/eluser]
It works to me thanks for Your code share here .we can use autocomplete plugin in codeigniter ,i used that to display , it will displayed data which is in not table also , i cant find reason.if anyone use the autocomplete plugin which is work correctly to u post here . with ui autocomplete works great to me


Thanks
A.Sona

#42
[eluser]pickupman[/eluser]
[quote author="josebyte" date="1286542925"]The code works, thanks!!
I haven´t any idea of jquery but resolved the problem using function() before autocomplete:
[/quote]

That's the onload js call for jQuery to actually load. You need that with any jQuery script.

#43
[eluser]LeonLanford[/eluser]
Hi, I'm new to codeigniter and ajax+jquery.
I'm now trying to implement the autocomplete jquery ui but I got a problem.

If the search doesn't return any result, the loading image is still there. (first image)
If the search return result but then I put more characters then the box will stuck there and the loading image still there. (second image)

The image only will be gone if I choose a returned result.
This doesn't occur if I don't use codeigniter.

My controller code
Code:
function search()
    {
        $kalimat = $this->input->post('term');
        
        $dorong_array = array();
        $dorong_array['respon'] = 'false'; //Set response
        
            $this->load->model('submit_model');
            $query = $this->submit_model->get_search_like("global_genre", "nama_gg", $kalimat, 0);
            
            
            
            if (!empty($query))
            {
                $dorong_array['respon'] = 'true'; //Set response
                $dorong_array['mesej'] = array();
                
                for($i=0; $i<count($query); $i++)
                {
                    foreach ($query[$i] as $key => $value)
                    $dorong_array['mesej'][] = array('label'=> $value, 'value'=> $value); //Add a row to array
                }
            }
        
            echo json_encode($dorong_array);
    }

My javascript code in view
Code:
$(function() {
    function log( message ) {
        $( "<div/>" ).text( message ).prependTo( "#log" );
        $( "#log" ).attr( "scrollTop", 0 );
    }
        
    $( "#term" ).autocomplete({
        source: function(request, response) {
            $.ajax({
                url: '&lt;?php echo site_url('submit/search');?&gt;',
                data: request,
                dataType: "json",
                type: "post",
                success: function(data){
                    if(data.respon =='true'){
                           response(data.mesej);
                     }
                }
            });
        },
        minLength: 1,
        select: function( event, ui ) {
            log( ui.item ?
            "Selected: " + ui.item.value + " aka " + ui.item.id :
            "Nothing selected, input was " + this.value );
        }
    });

Hope someone can help me,
Thanks

#44
[eluser]pickupman[/eluser]
Are you using the older autocomplete plugin or the one part of the jQueryUI package? The code I have posted is using the jQueryUI autocomplete plugin. The names are the same which has caused confusion. I believe part of the code has been merged into the UI branch, which allows some similar syntax.

As far was with and without CI, seems a bit odd. Sometimes log() causes problems for me.

#45
[eluser]LeonLanford[/eluser]
[quote author="pickupman" date="1287622426"]Are you using the older autocomplete plugin or the one part of the jQueryUI package? The code I have posted is using the jQueryUI autocomplete plugin. The names are the same which has caused confusion. I believe part of the code has been merged into the UI branch, which allows some similar syntax.

As far was with and without CI, seems a bit odd. Sometimes log() causes problems for me.[/quote]

I think I'm using the latest one (just downloaded it today)
Code:
* jQuery UI Autocomplete 1.8.5
*
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license

I tried to remove the log() function but it still error like that.
Like I said above, it's working perfectly without codeigniter, I don't know why it's error on codeigniter.. Sad

#46
[eluser]kakap[/eluser]
hello guys, i need your help Smile this is my scripts

controller:
Code:
function film_lookup() {
        
        //ambil judul film
        $this->load->model('mfilm');
        
        $keyword = $this->input->post('term');
        
        $data['response'] = 'false';
        
        $query = $this->mfilm->getFilmTitle($keyword);
        
        if (!empty($query)) {
            
            $data['response'] = 'true';
            $data['message'] = array();
            
            foreach ($query as $row) {
                
                $data['message'][] = array(
                                     'id' => $row->id_film,
                                     'value' => $row->judul_film,
                                     ''
                                     );
                
            }
            
        }
        
        if ('IS_AJAX') {
            
            echo json_encode($data);
            
        }
    }

my model:
Code:
function getFilmTitle($keyword) {
        
        //autocomplete
        $this->db->select('id_film, judul_film')->from('film')
                 ->where('show', '1')
                 ->like('judul_film', $keyword, 'after');
                
        $Q = $this->db->get();
        
        return $Q->result();
        
    }

my view:

Code:
[removed]
        $(this).ready(function() {
            
        $("#judul_film").autocomplete({
        
        minLength: 1,
        source: function(req, add) {
            
            $.ajax({
                
                url: "&lt;?php echo base_url();?&gt;index.php/member/film_lookup",
                dataType: 'json',
                type: 'POST',
                data: req,
                success: function(data) {
                    
                    if (data.response == 'true') {
                        
                        add(data.message);
                        
                    }
                    
                },
                
            });
            
        },      
                      
    });
            
    });
    [removed]

&lt;?php echo form_open('member/create_review');?&gt;
    <p><label>Judul Film</label><br />
    &lt;?php
    $data = array('name' => 'judul_film', 'id' => 'judul_film', 'size' => '50');
    echo form_input($data);
?&gt;

autocomplete is already running, but i want to store 'id_film' to database, not 'judul_film'. how to change form input value to 'id_film'?

thanks for your help

judul_film = title_film Smile

#47
[eluser]pickupman[/eluser]
You already answered it yourselfSmile
Code:
$data = array('name' => 'id_film', 'id' => 'judul_film', 'size' => '50');

#48
[eluser]kakap[/eluser]
[quote author="pickupman" date="1310767168"]You already answered it yourselfSmile
Code:
$data = array('name' => 'id_film', 'id' => 'judul_film', 'size' => '50');
[/quote]

sorry, my english is bad Smile I mean like this:
i have data:
id_film | title
1 | transformer

from my scripts before, when someone type on input form.. ex. I type "t" then will show sugestion "transformer" then i select it. so the input form will have value "transformer", right?
&lt;input type="text" name="judul_film" id="judul_film" value="transformer" /&gt;

how to change value "transformer" to "id of transformer" ? which mean "1"
&lt;input type="text" name="judul_film" id="judul_film" value="1" /&gt;

i am going to send the value to another table which has 'integer' type field

i hope my this explenation is clear enough, thank you so much Smile

#49
[eluser]NotoriousWebmaster[/eluser]
Wow, this thread's been going for a LONG time!

I've been using the old version of autocomplete, before it got integrated into jQuery UI. But then I wanted to add a throbber as the AJAX call starts, and the old version wouldn't do that. So I've upgraded to the UI version. And, of course, that's when it all went pear-shaped.

So, my AJAX request is coming up with a 404. It looks like so:

http://ccsr.dev/index.php/ccsr/vp_autocomplete?term=be

I looked into setting up allowing query strings, but it seems to be an all or nothing type of deal: so every request would be with query strings rather than slashes (ie: domain/controller/method).

Any help would be welcome. Thanks in advance,
- AAA

#50
[eluser]pickupman[/eluser]
@NotoriousWebmaster
Hopefully your are on CI2.0, and if so you may need to enable the ? in your permitted uri characters. If that is enabled, sometimes you need to adjust uri_protocol to find what suits your server environment. Usually one of the two should help you allow a query string.

The earlier posted methods was a way around, but still work, for getting past using GET strings. If you can allow the ? parameter, try using [url="http://php.net/manual/en/function.parse-str.php"]parse_str()[/url].


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.