<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Johan Känngård &#187; Prototype</title>
	<atom:link href="http://johankanngard.net/tag/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://johankanngard.net</link>
	<description>Useful tips for developers</description>
	<lastBuildDate>Thu, 19 May 2011 18:40:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Simple Combobox using Autocompleter.Local from Script.aculo.us</title>
		<link>http://johankanngard.net/2008/10/08/simple-combobox-using-autocompleterlocal-from-scriptaculous/</link>
		<comments>http://johankanngard.net/2008/10/08/simple-combobox-using-autocompleterlocal-from-scriptaculous/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 13:19:20 +0000</pubDate>
		<dc:creator>Johan Känngård</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Script.aculo.us]]></category>

		<guid isPermaLink="false">http://johankanngard.net/?p=302</guid>
		<description><![CDATA[The Autocompleter.Local in the Script.aculo.us Prototype-addon is quite nice. It can be used to get type-ahead into a field if you have a local JavaScript Array. I wanted to extend the functionality to have it behave as a Combobox, which is like a Select with a text input field. Here is how I did it, [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://github.com/madrobby/scriptaculous/wikis/autocompleter-local">Autocompleter.Local</a> in the <a href="http://script.aculo.us/">Script.aculo.us</a> <a href="http://www.prototypejs.org">Prototype</a>-addon is quite nice. It can be used to get type-ahead into a field if you have a local JavaScript Array. I wanted to extend the functionality to have it behave as a Combobox, which is like a Select with a text input field. Here is how I did it, be advised it has some bugs, let me know if you have a better solution!<br />
<code><br />
var Combobox={};<br />
Combobox.Local=Class.create(Autocompleter.Local,{<br />
	initialize:function($super,element,update,array,options){<br />
		$super(element,update,array,options);<br />
		this.options.minChars=this.options.minChars||0;<br />
		Event.observe(this.element,'click',this.onClick.bindAsEventListener(this));<br />
	},<br />
	onClick:function($super,event){<br />
		if(Event.element(event).id){<br />
			if(this.active){<br />
				this.hasFocus=false;<br />
				this.active=false;<br />
				this.hide();<br />
			}else{<br />
				this.activate();<br />
				this.render();<br />
			}<br />
			return;<br />
		}<br />
		$super(event);<br />
  }<br />
});<br />
</code><br />
The CSS I use is a modified variant of the <a href="http://github.com/madrobby/scriptaculous/wikis/autocompleter-local">Autocompleter.Local wiki page</a>:<br />
<code><br />
.combo {<br />
	background-image:url(combo_select2.gif);<br />
	background-repeat:no-repeat;<br />
	background-position:right top;<br />
	margin-right:10px;<br />
}</p>
<p>.combo:hover {<br />
	background-image:url(combo_select2.gif);<br />
	background-repeat:no-repeat;<br />
	background-position:right -18px;<br />
}</p>
<p>div#autocomplete {<br />
	margin:0px;<br />
	padding:0px;<br />
	width:250px;<br />
	background:#fff;<br />
	border:1px solid #888;<br />
	position:absolute;<br />
}</p>
<p>div#autocomplete ul {<br />
	margin:0px;<br />
	padding:0px;<br />
	list-style-type:none;<br />
}</p>
<p>div#autocomplete ul li.selected {<br />
	background-color:#ffb;<br />
}</p>
<p>div#autocomplete ul li {<br />
	margin:0;<br />
	padding:2px;<br />
	height:12px;<br />
	display:block;<br />
	list-style-type:none;<br />
	cursor:pointer;<br />
}<br />
</code><br />
Usage:<br />
<code><br />
new Combobox.Local('textFieldID','outputDivID',array,options);<br />
</code><br />
Example JavaScript:<br />
<code><br />
var cities=new Array('Stockholm','Göteborg','Kiruna');<br />
new Combobox.Local(<br />
	'cityField',<br />
	'autocomplete',<br />
	cities,<br />
	{<br />
		partialSearch:true,<br />
		fullSearch:true,<br />
		partialChars:0,<br />
		minChars:0<br />
	}<br />
);<br />
</code><br />
Example HTML:<br />
<code></p>
<input type="text" id="cityField">
<div id="autocomplete"></div>
<p></code><br />
The Windows XP style combobox image referenced in the CSS can be found here:<br />
<img src="http://johankanngard.net/wp-content/uploads/2008/10/combo_select2.gif"></p>
]]></content:encoded>
			<wfw:commentRss>http://johankanngard.net/2008/10/08/simple-combobox-using-autocompleterlocal-from-scriptaculous/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

