<?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>Belfry Images &#187; UI</title>
	<atom:link href="http://blog.belfryimages.com.au/category/ui/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.belfryimages.com.au</link>
	<description>Ben Scott's personal blog</description>
	<lastBuildDate>Fri, 20 Aug 2010 22:31:26 +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>Using Jeditable for inline editing</title>
		<link>http://blog.belfryimages.com.au/2010/02/04/using-jeditable-for-inline-editing/</link>
		<comments>http://blog.belfryimages.com.au/2010/02/04/using-jeditable-for-inline-editing/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 15:02:43 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[HTML/XHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.belfryimages.com.au/?p=255</guid>
		<description><![CDATA[Using the Jeditable plugin for jQuery enables inline editing of a block of text. This makes it easy to take a static view and simply drop in editability. Say we start with the following HTML: &#60;label&#62;Name:&#60;/label&#62; &#60;span class=&#34;employeeName&#34;&#62;Ben Scott&#60;/span&#62;&#60;br/&#62; &#60;label&#62;Rating:&#60;/label&#62; &#60;span class=&#34;employeeRating&#34;&#62;Highly awesome&#60;/span&#62; We want to be able to edit the employeeName and employeeRating spans. [...]]]></description>
			<content:encoded><![CDATA[<p>Using the <a href="http://www.appelsiini.net/projects/jeditable">Jeditable</a> plugin for <a href="http://jquery.com/">jQuery</a> enables inline editing of a block of text. This makes it easy to take a static view and simply drop in editability. Say we start with the following HTML:</p>
<pre class="brush: html">
&lt;label&gt;Name:&lt;/label&gt; &lt;span class=&quot;employeeName&quot;&gt;Ben Scott&lt;/span&gt;&lt;br/&gt;
&lt;label&gt;Rating:&lt;/label&gt; &lt;span class=&quot;employeeRating&quot;&gt;Highly awesome&lt;/span&gt;
</pre>
<p>We want to be able to edit the <code>employeeName</code> and <code>employeeRating</code> spans. We need two actions (asssuming an MVC framework) to update the name and rating. The URLs might be something like <code>/employee/set_name/{id}</code> and <code>/employee/set_rating/{id}</code>. Each action should accept HTTP POST, take the new value in <code>$_REQUEST['new_value']</code> or similar, and return a HTTP status of 200 on success and 500 on failure, with the error message in the response. For example, using Slab (my PHP5 MVC framework, in development) the <code>set_name</code> action might be like this:</p>
<pre class="brush: php">
class EmployeeController extends AppController {
	function set_name($id) {
		$this-&gt;Employee-&gt;save(array(
			'id' =&gt; $id',
			'name' =&gt; $this-&gt;data['new_value']);
		));
		return $this-&gt;ajaxSuccess($this-&gt;data['new_value']);
	}
}
</pre>
<p>Slab catches uncaught exceptions and returns an AJAX failure with the exception message as the body of the response.</p>
<p>To hook up the fields to the actions, modify the HTML to include the URLs to the actions. While this means the markup has behavioural elements and isn&#8217;t purely presentational (and has a non-standard attribute), it makes the script a bit simpler and easy to move into a static .js file, and is a quick way to get a page working.</p>
<pre class="brush: html">
&lt;label&gt;Name:&lt;/label&gt; &lt;span class=&quot;employeeName&quot; editUrl=&quot;/employee/set_name/7&quot;&gt;Ben Scott&lt;/span&gt;&lt;br/&gt;
&lt;label&gt;Rating:&lt;/label&gt; &lt;span class=&quot;employeeRating&quot; editUrl=&quot;/employee/set_rating/7&quot;&gt;Highly awesome&lt;/span&gt;
</pre>
<p>Now for the script itself:</p>
<pre class="brush: javascript">
$(function(){
	$('.employeeName, .employeeRating').editable(
		function(value, settings) {
			return $.ajax({
				url: $(this).attr('editUrl'),
				data: { 'new_value': value },
				async: false,
				type: 'post'
			}).responseText;
		}, {
			indicator: 'Saving...',
			tooltip: 'Click to edit',
			onblur: 'submit'
		}
	);
});
</pre>
<p>The first argument is a function that returns the new value of the field. This is important when doing things like replacing line breaks with <code>&lt;br/&gt;</code> which we&#8217;re not worrying about, but it also gives us the ability to write our own AJAX code. By default Jeditable makes assumptions about how the update is done. The <code>async</code> option in the call to <code>$.ajax()</code> blocks until the call returns, and lets the function return the response of the AJAX call. The second argument are options to set some text to show while calling the update function, the tooltip to display when hovering over the span, and to submit changes on blurring the input which makes it seem a bit more usable when there are multiple fields.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.belfryimages.com.au/2010/02/04/using-jeditable-for-inline-editing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Form validation with jQuery</title>
		<link>http://blog.belfryimages.com.au/2009/12/09/form-validation-with-jquery/</link>
		<comments>http://blog.belfryimages.com.au/2009/12/09/form-validation-with-jquery/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 09:40:50 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[HTML/XHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.belfryimages.com.au/?p=204</guid>
		<description><![CDATA[Every time I&#8217;ve implemented client-side form validation I&#8217;ve started from scratch and done it a little differently. Usually it devolves into a messy set of if statements and duplicated code. Here&#8217;s my latest method, which separates the validation rules from the processing. It uses jQuery because if you&#8217;re not using a Javascript library you should [...]]]></description>
			<content:encoded><![CDATA[<p>Every time I&#8217;ve implemented client-side form validation I&#8217;ve started from scratch and done it a little differently. Usually it devolves into a messy set of <code>if</code> statements and duplicated code. Here&#8217;s my latest method, which separates the validation rules from the processing. It uses <a href="http://jquery.com">jQuery</a> because if you&#8217;re not using a Javascript library <a href="http://www.codinghorror.com/blog/archives/001275.html">you should be</a>. This will only handle relatively simple validation cases.</p>
<p>So start with a form:</p>
<pre class="brush: html">
	&lt;form id="mailingListSubscription" action="subscribe.php"&gt;
		Name: &lt;input type="text" name="name" id="name" /&gt;&lt;br /&gt;
		Email: &lt;input type="text" name="email" id="email" /&gt;&lt;br /&gt;
		Phone: &lt;input type="text" name="phone" id="phone" /&gt;&lt;br /&gt;
		&lt;button type="submit"&gt;Subscribe&lt;/button&gt;
	&lt;/form&gt;
</pre>
<p>All fields are required, and I&#8217;m going to use some magical regex (found on the interthingy somewhere) to validate the email address. This script sets up the rules:</p>
<pre class="brush: javascript">
	var rules = [
		{ id: 'name', test: function(val) { return val != ''; }, msg: 'Please enter your name' },
		{ id: 'email', test: function(val) { return val.search(/^[^@]+@[^@]+.[a-z]{2,}$/i) != -1; }, msg: 'Please enter a valid email address' },
		{ id: 'phone', test: function(val) { return val != ''; }, msg: 'Please enter your phone number' }
	];
</pre>
<p>Each rule has the id of the form element being tested, a message that gets displayed on failing the rule, and a function that validates the value of the form element. I also could add multiple rules for the one input.</p>
<p>This script sets up the <code>submit</code> handler for the form, which does the validation using the array of rules set up above:</p>
<pre class="brush: javascript">
	$(function(){
		$('form#mailingListSubscription').submit(function(){
			for (var i = 0; i &lt; rules.length; i ++) {
				var rule = rules[i];
				var target = $('#'+rule.id);
				if (!rule.test(target.val())) {
					alert(rule.msg);
					target.focus();
					return false;
				}
			}
			return true;
		});
	});
</pre>
<p>On a test failing, the rule&#8217;s <code>msg</code> value is shown and the target of the test gets focus. This could be changed to something more user friendly like showing the message next to the target field.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.belfryimages.com.au/2009/12/09/form-validation-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZedGraph &#8211; .NET graph control</title>
		<link>http://blog.belfryimages.com.au/2008/03/28/zedgraph-net-graph-control/</link>
		<comments>http://blog.belfryimages.com.au/2008/03/28/zedgraph-net-graph-control/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 09:56:58 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://belfryimages.com.au/2008/03/28/zedgraph-net-graph-control/</guid>
		<description><![CDATA[Today I needed a graphing control, and with a bit of searching found ZedGraph. This has got to be the best open source .NET component I&#8217;ve ever used. All you need to do is reference the .DLL, drop a ZedGraph control onto your form or control, and add some code to load in a data [...]]]></description>
			<content:encoded><![CDATA[<p>Today I needed a graphing control, and with a bit of searching found <a href="http://zedgraph.org">ZedGraph</a>. This has got to be the best open source .NET component I&#8217;ve ever used. All you need to do is reference the .DLL, drop a ZedGraph control onto your form or control, and add some code to load in a data range. It&#8217;s even easier to make a pie chart and the colours, gradients, etc., are all customisable. Out of the box the control automatically has zooming, scaling, printing and exporting features accessible to the user, and it looks nice and clean. There&#8217;s also a ZedGraphWeb control built in which is for use in ASP.NET apps (although I haven&#8217;t tried that out).</p>
<p>There are two concurrent versions for both .NET 1.1 and .NET 2 (which is very handy since I&#8217;m limited to .NET 1.1 at work). The only difference between the versions is apparently use of templates for collections.</p>
<p>There&#8217;s a <a href="http://www.codeproject.com/KB/graphics/zedgraph.aspx">CodeProject article</a> that gives a pile of simple demo code, and the <a href="http://zedgraph.org">main site</a> is a Wiki with what looks like plenty of documentation. The library is licensed under the LGPL license, which means that derivative works must be LGPLed, but as long as the library&#8217;s DLLs are dynamically linked they can be included in commercial software.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.belfryimages.com.au/2008/03/28/zedgraph-net-graph-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
