<?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>Mike Cravey</title>
	<atom:link href="http://craveytrain.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://craveytrain.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 18 Jun 2009 05:14:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Accessible Inline Form Labels</title>
		<link>http://craveytrain.com/accessible-inline-form-labels/</link>
		<comments>http://craveytrain.com/accessible-inline-form-labels/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 18:31:40 +0000</pubDate>
		<dc:creator>craveytrain</dc:creator>
				<category><![CDATA[Techniques]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[labels]]></category>

		<guid isPermaLink="false">http://craveytrain.com/?p=45</guid>
		<description><![CDATA[Accessibly turn regular form labels into inline form labels using a little progressive enhancement and a touch of unobtrusive JavaScript.]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> Added the check to make sure the input is empty before showing the overlayed label the first time.</p>
<p>I recently read <a href="http://trevordavis.net">Trevor Davis</a>&#8216; post on <a href="http://trevordavis.net/blog/tutorial/jquery-inline-form-labels/">inline form labels</a>. First off, I have the utmost respect for TD. I read his blog regularly and have learned a lot from his posts. While I respect the work he has done for his plugin, I approach things differently. I am a UX Architect for a government site so I have significant concerns about accessibility, semantics and progressive enhancement.</p>
<p>My approach differs from him in 2 main facets:</p>
<ol>
<li>He is pulling his inline form label value from the title attribute. I am using the actual label. I feel this is more semantic.</li>
<li>He is adding and removing a value to the form field. This can cause validation and styling issues. I am going to overlay the label on to the form field therefore not mucking with the value of the field.</li>
</ol>
<p>That is not to say my technique is not without issue. It relies on good support of the CSS box model.</p>
<h3>Markup</h3>
<pre class="code">	<code class="html">
		&lt;form id="contact"&gt;
			&lt;ul&gt;
				&lt;li&gt;
					&lt;label for="name"&gt;Name&lt;/label&gt;
					&lt;input type="text" id="name" name="name" value="" /&gt;
				&lt;/li&gt;
				&lt;li&gt;
					&lt;label for="email"&gt;Email&lt;/label&gt;
					&lt;input type="text" id="email" name="email" value="" /&gt;
				&lt;/li&gt;
				&lt;li&gt;
					&lt;label for="verbiage"&gt;Message…&lt;/label&gt;
					&lt;textarea id="verbiage" name="verbiage" rows="5" cols="25"&gt;&lt;/textarea&gt;
				&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/form&gt;
	</code></pre>
<p>Simple markup, just your basic form. I&#8217;m an unordered list guy for forms, but certainly your favorite method of marking up forms should be fine. Except for tables, cause that&#8217;s just wrong.</p>
<h3>Stylings</h3>
<pre class="code">	<code class="css">
		form li {
			line-height: 1.5;
			margin-bottom: 1.5em;
			position: relative;
		}

		form label.overlayed {
			position: absolute;
			top: .15em;
			left: .5em;
			white-space: nowrap;
			color: #999;
		}
	</code></pre>
<p>Again, simple stuff, note the <code>position: relative</code> on the <code>li</code>. That&#8217;s sets a bounding box for everything inside of it. Then we are free to use <code>position:absolute</code> for the <code>label</code> (when overlayed). That effectively removes it from layout allowing the inputs to slide left (or up, depending on your form layout).</p>
<p>Notice the use of the <code>overlayed</code> class. I could just style the labels this way by default, but the whole technique here needs javascript. As a general rule of thumb, <em>I use the same technology to add something as I use to manipulate it</em>. Since I will need JavaScript to manipulate the label visibility, I will use JavaScript to put it in position to begin with. I could have styled the label in a default manner (left of the input, above the input, etc) but chose not to for simplicity&#8217;s sake.</p>
<h3>Scripting</h3>
<pre class="code">	<code class="js">
	var oTxtFields = $('input,textarea');
	$.each(oTxtFields, function(){
		var label = $('label[for=' + $(this).attr('id') + ']');
		label.addClass('overlayed');
		if (!$(this).val() == '') {
			label.hide();
		}
		$(this)
			.focus(function(e){
				$('label[for=' + $(e.target).attr('id') + ']').hide();
			})
			.blur(function(e){
				if ($(e.target).val() == '') {
					$('label[for=' + $(e.target).attr('id') + ']').show();
				}
			})
		;
	});
	</code></pre>
<p>This code is relatively simple as well but let me point out a few things. Obviously this is assuming jQuery is loaded. Setting a native object for the form elements saves a lot of processing time. Doing the jQuery lookup every time you reference the object is very expensive. Do it once and store it to an object.</p>
<p>Moving on, for each form element set a label variable based on the associated <code>label</code> tag then add the class <code>overlayed</code> to the label. This will position the label inside the form field. Since JavaScript is needed for this technique, we want to initialize the whole thing with JavaScript. You don&#8217;t want to end up in a situation where the user has stylesheets capabilities but not Javascript leaving them with an overlayed label and no way to hide it.</p>
<p>Finally we add some event listeners for each form field. The first is a focus which does a lookup on the label associated with the field that has focus and hides it using <a href="http://docs.jquery.com/Effects/hide">jQuery&#8217;s hide method</a>.</p>
<p>The second event listener added is for blur. If, on blur, the form field value attribute is empty we show the associated label using <a href="http://docs.jquery.com/Effects/show">jQuery&#8217;s show method</a>.</p>
<p>That&#8217;s about it. I hope you found this technique useful. If nothing else, maybe you found this to be an alternative to Trevor&#8217;s inline form label technique. If I get enough interest I will look into creating a jQuery plugin for this. Feel free to wholesale reuse this technique. I hardly coined it, I just blogged it.</p>
]]></content:encoded>
			<wfw:commentRss>http://craveytrain.com/accessible-inline-form-labels/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Adventures in Honeymooning: Bidet</title>
		<link>http://craveytrain.com/bidet/</link>
		<comments>http://craveytrain.com/bidet/#comments</comments>
		<pubDate>Thu, 07 Dec 2006 01:24:18 +0000</pubDate>
		<dc:creator>craveytrain</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://craveytrain.com/?p=32</guid>
		<description><![CDATA[We are back and it was a great, albeit long, trip. It was a beautiful wedding and a blissful honeymoon. However, I have tales to tell. Really, just my perspective on things. Though these aren’t in chronological order, I thought I would start with the story that has been told a couple times already so [...]]]></description>
			<content:encoded><![CDATA[<p>We are back and it was a great, albeit long, trip. It was a beautiful wedding and a blissful honeymoon. However, I have tales to tell. Really, just my perspective on things. Though these aren’t in chronological order, I thought I would start with the story that has been told a couple times already so it has some form.</p>
<p>“And here is your <a href="http://en.wikipedia.org/wiki/Bidet">bidet</a>” our butler told us as he gave us a tour of our villa. I had heard of a bidet, but I had never actually seen one. See, down in Texas, we uh… just use paper. And admittedly, even in my time traveling, I have never happened across one. I knew what it was for, and honestly, I was curious. I was determined to figure it out.</p>
<p>I took a gander at it, it had a hot water knob on the left, a cold water knob on the right and a knob in the middle. Ok, not unlike a shower. There’s a bulbous looking water spout in the bottom of the bowl. It’s like an upside down shower head. Ok, I see where this is going. Or so I thought.</p>
<p>After dancing around the idea of trying it out for a day or so, the humidity and just perpetual sweating got the best of me. I was gonna give it a shot (no pun intended). So, turn on the hot water, it starts filling up the bowl from the sides similar to how a toilet does when you flush it. Well, I do know what this device is for, and I’m not about to stick my hands down in that bowl. So I add a little cold to try to get a warm water. I turn the middle knob just a bit, to try to get a water fountain effect. Just high enough for me to feel the water without having to dunk my hand in the bowl. Seemed ok.</p>
<p>Then I really started to consider how to use this apparatus. I mean, how do you mount this thing? I see the knobs are in the back, do you face the knobs so you have control? But it’s shaped like a toilet bowl, so I sit like I would on a toilet bowl? But that means I have to reach behind me to control the temperature and water pressure. That doesn’t seem natural. Then I really notice something that threw me off and ended up being my demise.</p>
<p>There is no seat on this thing. It’s like a toilet without a seat. Just a porcelain bowl. I have visions of what the toilet bowl can look like in my house with the seat up and decide, there is no way I’m sitting directly on that. It looks clean enough, sure. But still, no way. Turns out, that was exactly what I should have done.</p>
<p>So, I decide to do the chick thing and squat over it. Unfortunately, I forgot to take gravity into consideration in all this. I got into what I thought was position and turned up the water pressure. That’s where things got messy.</p>
<p>First off, I initially missed. When I say I missed, I mean I was soaking my inner thigh. Just totally missed the important parts all together. Ok, adjust. But wait, why was my calf wet? Crap, I didn’t squat down far enough, the water is running down my leg. And into my shoes. Yes, at my ankles were my underwear, my pants, socks and shoes, now totally soaked. So now I’m reaching behind me, looking for the water pressure knob to turn it off and that is causing me to move and water is spraying everywhere. Both legs, up my shirt, up my nose, even in my hair (turns out I had the water pressure up way higher than it needed to be). By the time I get it turned off, I am completely soaked from head to toe and there is standing water in the toilet room. It’s leaking out under the door and my wife is asking what the hell I am doing in there. Thankfully I had the door locked so she couldn’t come in and see for herself. I went straight to the shower, did not pass go, did not collect $200.</p>
<p>Since then I have looked up how to use it and if I encounter one again, I may actually try it again, maybe.</p>
]]></content:encoded>
			<wfw:commentRss>http://craveytrain.com/bidet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
