Yii CJuiAutoC Set default display value and clear it by clicking

I have CJuiAutoComplete below, and when I boot, I want to display β€œSearch” in the text box and on click I want to clear. I tried using the "value" in the parameters, but could not get it to 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',) )); ?> 

Hi

UPDATE

direct "value" => "search" worked.

Click Handler Verification

Kiran

+6
source share
2 answers

What you can do is provide your widget with an identifier, then put the onClick event in the onClick widget and with 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, since these are jQuery parameters for CJuiAutocomplete , onClick is not defined in JUI autocomplete options .

Greetings

+11
source

An old thread, but for beginners who land here, its just adding the html placeholder attribute to Yii CAutoComplete. See the code below and add the line htmloptions:

 <?php $this->widget('CAutoComplete', array( 'model'=>$model, 'attribute'=>'tags', 'url'=>array('suggestTags'), 'multiple'=>true, 'htmlOptions'=>array('size'=>50,'placeholder'=>'Seperate tags with commas'), )); ?> 
0
source

Source: https://habr.com/ru/post/897564/


All Articles