AutoComplete

Hello guys. I am working at CJuiAutoComplete. Now this is my function in controller




public function actionAutoCompTest($term)

{

    $keywords = end(explode(', ',$term));

    $term = $keywords;

    $data = RFI::model()->findAll("rfi_no LIKE '%" . $term . "%'");

    foreach ($data as $m)

    {

        $results[] = array('id' => $m->id, 'value' => $m->rfi_no);

    }

    echo CJSON::encode($results);

}



and this is my widget




<?php

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

    'id'=>'rfi_no',

    'name'=>'rfi_no',

    'sourceUrl'=>$this->createUrl('RFIs/autoCompTest'),

    'htmlOptions'=>array(

        'size'=>'30'

    ),

    'options'=>array(

                     'showAnim'=>'fold',

                    'focus'=>'js:function( event, ui ) {

                            $( "#rfi_no" ).val(ui.item.value);

                            return false;

                            }',

                     'select'=>'js:function(event, ui) {

                                $("#rfi_id").val($("#rfi_id").val()+ " - " + ui.item.id);

                            }',

        ),

));

?>



i want to set rfi_no textbox (in whcih suggestion is placing) empty after selection.

any idea what option should be used for that or can we do it in select option??

also i tried to $(’#rfi_no’).val(’’); in select option but it didn’t work.

Anybody??

Try adding:




    $("#rfi_id").val($("#rfi_id").val()+ " - " + ui.item.id);

 $("#rfi_no").val("");




Tried it but not working… also describe it in last of my topic

Still waiting for help dudes…

Just now I understood what you need…

So you would like to empty the input field after the value is selected…

To do that you need to use setTimeout() because the input field gets the selected value after ‘select’ is executed…




'select'=>'js:function(event, ui) {

	$("#rfi_id").val($("#rfi_id").val()+ " - " + ui.item.id);

	setTimeout(function(){$("#rfi_no").val("")},400);

}',



And the ‘focus’ part is not needed… you can completely remove it…