Autocomplete Bind Into Change Event

Hi,

I’ve been playing with CJuiAutoComeple modifying how it presents the results and so far I’ve been able to achieve everything I wanted however I have a problem and a question which I hope someone might know the answer here,

My code looks like this:




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

	'name'=>'toplivesearch',

	'source'=>$this->createUrl('/site/autocompleteTest'),

	'options'=>array(

			'minLength'	=> '3',

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

				console.log("Change Event");

				//dummy code

				$("#close-result").on("click",function(){

 					alert("hey");

				});

				//end dummy code

			}',

	),

	'htmlOptions'=>array(

		'placeholder'=>'Search',

		'class'=>'search-box',

		'size'=>'26',

	)

));



During the “change” event I want to be able to detect if an anchor is clicked, what happens is, “open” event opens the result window which has a close button, however as soon as I click on close the change event triggers and ignores my click, I’ve tried different approches with so successes, read bind() documentation and tried to implement it as well with no luck, any idea how I can do this?

Also, my javascript code turned out to be too big, this widget is basically about 2 pages long now with all the javascript codes, is there anyway to separate the javascript from this widget and make it an external file? that would also benefit me since I can use functions more easily and get rid of duplicated codes in different events.

Appreciate your help

Nick

To make first part of my question simpler, this is what I’m trying to do: http://codepen.io/anon/pen/gmsaH

First type something in the input box and then click on “test” link, as you can see the click is being ignored, how can I make it so ‘change’ event first checks to see if I have clicked on “test”, if yes do something, if not do whatever is default

I understand this has nothing to do with Yii and is purely javascript/jquery, reason I posted this question here was because of second part of my question which is separating javascript from the CJuiAutoComplete widget