{"id":164,"date":"2009-07-16T00:11:22","date_gmt":"2009-07-15T11:11:22","guid":{"rendered":"http:\/\/www.thunderguy.com\/semicolon\/?p=164"},"modified":"2012-02-10T16:53:09","modified_gmt":"2012-02-10T03:53:09","slug":"simple-combo-box-jquery-plugin","status":"publish","type":"post","link":"https:\/\/thunderguy.com\/semicolon\/2009\/07\/16\/simple-combo-box-jquery-plugin\/","title":{"rendered":"Simple Combo Box jQuery plugin"},"content":{"rendered":"<p>I have just released <strong>simpleCombo<\/strong>, a <a href=\"http:\/\/jquery.com\/\">jQuery<\/a>-based combo box widget that is<\/p>\n<ul>\n<li>simple<\/li>\n<li>lightweight<\/li>\n<li>consistent with native widget look and feel<\/li>\n<\/ul>\n<p>You can try out some <a href=\"http:\/\/www.thunderguy.com\/semicolon\/resources\/simpleCombo-demo.html\">simpleCombo demos<\/a>, and <a href=\"http:\/\/plugins.jquery.com\/project\/simpleCombo\">download simpleCombo<\/a> from the <a href=\"http:\/\/plugins.jquery.com\/project\/simpleCombo\">simpleCombo project page<\/a> at <a href=\"http:\/\/jquery.com\/\">jquery.com<\/a>. For more details, read on.<!--more--><\/p>\n<p>There are many combo box web page widgets out there, but almost all the ones I&#8217;ve seen have the same flaw: they render themselves by stitching together various other widgets like select lists, text inputs, divs and so on. The results can look very stylish, but they tend to look different to native widgets. For example, <a href=\"http:\/\/www.dojotoolkit.org\/\">Dojo<\/a>&#8216;s <a href=\"http:\/\/www.dojotoolkit.org\/projects\/dijit\">Dijit<\/a> suite of widgets look nice, but they look quite different to native widgets. If you have one Dijit combo box on your page then everything else has to be a Dijit widget; otherwise your page will look like a room full of mismatched furniture. And as much as I can appreciate an eclectic decorating style, I don&#8217;t think it works so well on a web page.<\/p>\n<p>So, if you want to be consistent with native browser widgets then you&#8217;ll just have to use them. One jQuery combo box plugin (<a href=\"http:\/\/plugins.jquery.com\/project\/native-combo-box\">Native Combo Box<\/a>) is implemented by putting a text input over the top of a select list. It has to sniff the browser type to position the text box correctly, and even then it&#8217;s not perfect: it looks great in IE but not so good in Firefox. I thought it would be a good idea to try just to use a plain select list, and add JavaScript to capture keystrokes and fake a text input that way. So <strong>jquery.simpleCombo<\/strong> was born.<\/p>\n<p>I have done a fair amount of testing with my limited resources. The jquery.simpleCombo plugin has the &#8220;<strong><abbr title=\"Works on Firefox and Internet Explorer\">woffie<\/abbr><\/strong>&#8221; property (works on Firefox and Internet Explorer). It also works on WebKit browsers such as Chrome and Safari. On these browsers you can&#8217;t type into the combo box when the list is &#8220;dropped down&#8221; &#8212; you have to click it or press escape to make the list go away before you can type.<\/p>\n<p>I have also put together a <a href=\"http:\/\/bennettmcelwee.github.com\/Simple-Combo\/simpleCombo-test.html\">simpleCombo test suite<\/a> using <a href=\"http:\/\/docs.jquery.com\/QUnit\">QUnit<\/a>. It verifies that the plugin correctly manipulates the DOM when creating the combo box, but I&#8217;m not sure how to use it to test user interaction in a meaningful way. I will investigate testing options further when I have some spare time (cue hollow laughter).<\/p>\n<p>After I wrote this, I discovered another plugin that uses the same idea. <a href=\"http:\/\/plugins.jquery.com\/project\/jEC\">Editable Combobox<\/a> is far, far more complex and has many options. It&#8217;s overkill for anything I need &#8212; it allows you to control the position of the edit item within the list, and also shows a blinking cursor on some browsers. In contrast, Simple Combo is so simple that it offers no configuration options at all. I drew inspiration here from <a href=\"http:\/\/www.antoinedesaintexupery.com\/\">Antoine de Saint-Exup\u00e9ry<\/a>, who said that perfection is attained not when no more can be added, but when no more can be removed.<\/p>\n<p>As part of developing this plugin I discovered a bug in jQuery 1.3.2. The bug occurs because <code>val()<\/code> will select every matching option in a select list, even if it&#8217;s a single select list (as most are). When this happens the browser has to make its own mind up about which option should be selected. Guess what? Internet Explorer and Firefox and Safari have differing views on the matter. I had to include a workaround for this problem in the plugin, and I have submitted a patch to the jQuery team to fix it (<a href=\"http:\/\/dev.jquery.com\/ticket\/4878\">Ticket 4878<\/a>).<\/p>\n<p>After all that reading, you&#8217;ll be keen to go to the <a href=\"http:\/\/plugins.jquery.com\/project\/simpleCombo\">simpleCombo project page<\/a> to download it. Off you go then.<\/p>\n<h2>Update<\/h2>\n<p><a href=\"http:\/\/bennettmcelwee.github.com\/Simple-Combo\/\">Simple Combo is now on Github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have just released simpleCombo, a jQuery-based combo box widget that is simple lightweight consistent with native widget look and feel You can try out some simpleCombo demos, and download simpleCombo from the simpleCombo project page at jquery.com. For more details, read on.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[21,40],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-general","tag-javascript","tag-jquery"],"_links":{"self":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":15,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/164\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}