Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii CJuiAutoComplete default display value and clearing it on click

I have below CJuiAutoComplete and when loading I want to display "Search" in the text field and on click I want to clear . I tried using "value" under options , but couldn't make it work . Thanks for your help

tried also

'htmlOptions'=>array('value'=>'Search',)

<?php

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'name'=>'test1',
   'source'=>'js: function(request, response) {
       $.ajax({
           url: "'.$this->createUrl('myAutoComplete/autoCompleate').'",
           dataType: "json",
           data: {
               term: request.term,
               brand: $("#type").val()
           },
           success: function (data) {
                   response(data);
           }
       })
    }',

     'options' => array(
                    'showAnim' => 'fold',
                    'select' => 'js:function(event, ui){ alert(ui.item.value) }',
                    'click'=>'js:function( event, ui ) {
                          alert("test");
                                    return false;
                                }',
     ),
    'htmlOptions'=>array('value'=>'Search',)
));
?>

Regards

UPDATE

directly putting 'value' =>'Search' worked .

Checking for click handler

Kiran

like image 380
Bujji Avatar asked Sep 18 '11 11:09

Bujji


1 Answers

What you can do is give your widget an id and then you place the onClick event in the widget's htmlOptions and using JavaScript you clear the value.

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'id'  => 'test1_id',
    'name'=> 'test1',
    'source'=>'js: function(request, response) {
    $.ajax({
        url: "'.$this->createUrl('myAutoComplete/autoCompleate').'",
        dataType: "json",
        data: {
            term: request.term,
            brand: $("#type").val()
        },
        success: function (data) {
            response(data);
        }
    })
}',
'options' => array(
    'showAnim' => 'fold',
    'select' => 'js:function(event, ui){ alert(ui.item.value) }',
),
'htmlOptions' => array(
    'onClick' => 'document.getElementById("test1_id").value=""'
)
));

You cannot put onClick in the options attribute as these are jQuery options for the CJuiAutocomplete, onClick is not defined in the JUI Autocomplete options.

Cheers

like image 161
ivantxo Avatar answered Nov 24 '22 15:11

ivantxo