CAutoComplete is not working in IE

When i open one of my items with the tag playground.

The value of the autocomplete textfield in my form will be "playground, " (without quotes). When i type swimmingpool and select that one from the auto complete list the value of the field will change to: "swimmingpool, swim, " instead of "playground, swimmingpool, ".

In FireFox this is working perfect…




<?php 

$optionsTag = array(

    'name' => 'Daytrip[Tags]',

    'url' => array('tag/autocompletetag'), 

    'max' => 10,

    'minChars' => 2, 

    'delay' => 500,

    'matchCase' => false,

    'multiple' => true,

    'value' => ('' != $daytrip->Tags) ? $daytrip->Tags . ', ' : '',

);

$this->widget('CAutoComplete', $optionsTag);

?>



I am having the same problem - anyone found a solution?

I also tried upgrading to 1.1.1 and now autocomplete doesn’t work at all. It doesn’t even try to do AJAX or give any JS errors in either IE or Firefox - its simply does nothing (tried deleting the assets folders in case it was a cache issue).




$this->widget('CAutoComplete', array(

  'model'=>$model,

  'attribute'=>'features',

  'url'=>array('suggestFeatures'),

  'multiple'=>true,

  'htmlOptions'=>array('size'=>50),

));



With 1.1.0, IE does actually work if you select the option from the suggested list using the up/down keys, but if you select using the MOUSE, it screws up - the new selection overwrites the first and leaves the typed characters at the end. Maybe some issue with the cursor position being changed to the start of the text box when you click the menu?

Regarding 1.1.1, I saw the other messsage about the conflict between Jui, so I assume that is why it doesn’t work at all. I agree about using an RC for JQuery and although I have read the note about using clientScript->scriptMap, I have to say that it is not very clear to me how to do this: could someone give an exact example of how to force it to use the old version?

Thanks!

I have used CAutoComplete in a couple of recent projects with no problem in IE.

Here is a working controller action for review if needed:


public function actionAutoCompleteLookup()

        {

           if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))

           {


              /* q is the default GET variable name that is used by

              / the autocomplete widget to pass in user input

              */

              $name = $_GET['q'];

              // this was set with the "max" attribute of the CAutoComplete widget

              $limit = min($_GET['limit'], 50);

              $criteria = new CDbCriteria;

              $criteria->select = "city";

              $criteria->distinct=true;       

              $criteria->condition = "city LIKE :sterm";

              $criteria->params = array(":sterm"=>"$name%");

              //$criteria->order = "city";

              $criteria->limit = $limit;

              $resultArray = geocity::model()->findAll($criteria);

              $returnVal = '';

              foreach($resultArray as $result)

              {

                 $returnVal .= $result->getAttribute('city'). "\n";

              }

              echo $returnVal;

           }

        }

What is in your controller?

Thanks, but I don’t think the controller is the issue - as I say it works perfectly with FF and it also happens with the Yii Blog Demo (which is where I copied the code from!). It always happens with Vista/W7+IE8 if you select using the mouse (rather than the arrow keys).

Hmm, I have W7+IE8 and it works fine for me.

Try this app I started work on some time ago (just proof of concept - currently on the shelf).

EDIT: removed link.

Select a country, type in a business type (‘plumber’ perhaps) and then a city/town (auto complete part).

Does it work for you?

Your one only allows a single choice - perhaps I didn’t explain that. This issue only happens with multiple selections - the 1st is always fine, but try adding a comma and a 2nd entry using the mouse…

(here: http://www.yiiframework.com/demos/blog/ add a new post and then try adding multiple tags)

outrage

Your jQuery is 1.3.2 so it’s probably being taken from assets that were set with previous version of Yii.

Hi Samdark,

You’re right, this was done some time ago but I’m working on another project with similar auto-complete on town/city - using only the latest Yii 1.1.1 and again it works fine in IE.

Add a new post and then try adding multiple tags selecting from the menu with the mouse:

http://www.yiiframework.com/demos/blog/

I see what you mean now :)

This seems to be a jQuery bug:

Official example page: http://jquery.bassistance.de/autocomplete/demo/json.html

OK, this can be fixed but it’s a bit of a hack.

Edit /framework/web/js/source/jquery.autocomplete.js

At line 221, comment out ‘return false;’ like so - //return false;

Save the file.

Delete contents of assets folder (cache).

Refresh.

Voila :)

Are there any side effects?

Only one that I can see.

It has the benefit of placing the cursor at the end of the line, instead of the beginning :)

It seems to works fine now in both FF & IE, not tried other browsers.

Well, placing cursor at the beginning of line should be quite irritating if we have multiple tags enabled.

Thanks for your help. Have you reported this as a bug to them? There is a TODO comment in the code (Line 226) about cursor positioning, so perhaps this is related.

[html]

// TODO this should set the cursor to the right position, but it gets overriden somewhere

//$.Autocompleter.Selection(input, progress + seperator, progress + seperator);

[/html]

Jörn Zaefferer is not going to support standalone version anymore but is accepting patches.

Here is a patch for 1.1.1:

http://code.google.com/p/yii/issues/detail?id=1048