﻿<?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>Programming By A Tool &#187; jQuery</title>
	<atom:link href="http://byatool.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://byatool.com</link>
	<description>This is my recorded stumbling through ASP.Net, Framework 3.5, C# 3.0, Ajax, Javascript, and Love.  Stay, learn, destroy.  It's your life.</description>
	<lastBuildDate>Thu, 03 May 2012 17:28:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>MVC3, Entity Framework, jQuery&#8230; Everything example</title>
		<link>http://byatool.com/lessons/mvc3-entity-framework-jquery-everything-example/</link>
		<comments>http://byatool.com/lessons/mvc3-entity-framework-jquery-everything-example/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 18:33:21 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Entity Framework 4]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery Validator]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[Mvc3]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=2110</guid>
		<description><![CDATA[How would you like to have a project that has these features? Dependency Injection Entity Framework 4.0 with POCO Inversion of Control with Castle The IResult jQuery jQuery Ajax Posts jQuery Custom Css jQuery Validation Mocking with Rhino Mocks MVC 3/Razor MVC Annotation Based Validation What I call the Repository Pattern Unit Tests - Integration [...]]]></description>
			<content:encoded><![CDATA[<p>How would you like to have a project that has these features?</p>
<pre>
Dependency Injection
Entity Framework 4.0 with POCO
Inversion of Control with Castle
<a href="http://byatool.com/Hosted/Tutorial/IResult.html" style="color:red;">The IResult</a>
jQuery
jQuery Ajax Posts
jQuery Custom Css
jQuery Validation
Mocking with Rhino Mocks
MVC 3/Razor
MVC Annotation Based Validation
What I call the Repository Pattern
Unit Tests - Integration With Entity Framework
Unit Test - MVC Controller Actions

And more s--t I can't think of right now!
</pre>
<p>What&#8217;s the price of this gem?  Just your time which is worth nothing!</p>
<p>Where can you find it?  <a href="http://byatool.com/Hosted/Tutorial/Mvc3Example.zip">Right here!</a></p>
<p>Requirements:</p>
<pre>
Visual Studios 4.0
<a href="http://www.asp.net/mvc/mvc3" style="color:red;">Mvc 3</a>
To open the solution and do a search and replace on "Tutorial" to set your directory paths.
A real f--king need to learn!
</pre>
<p>Act now, operators aren&#8217;t in existence since this is hosted on a website, but if they were they would be standing by!</p>
<p>Disclaimer:  </p>
<p>This may or may not hit you with a wave of awesome.  Be prepared for the worse case awesome scenario.  I am in now way responsible for any heart stoppage due to the shock and awe power of the project.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/lessons/mvc3-entity-framework-jquery-everything-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Validation with Multiple Checkboxes</title>
		<link>http://byatool.com/lessons/jquery-validation-with-multiple-checkboxes/</link>
		<comments>http://byatool.com/lessons/jquery-validation-with-multiple-checkboxes/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 16:05:30 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery Validator]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1941</guid>
		<description><![CDATA[So this one is done on request and because I am a kind of merciful god I will grant this request. For those bullet point programmers: The working demo can be found here The code can be easily downloaded Now when I say validation, I mean the validation plugin. and this example is built using [...]]]></description>
			<content:encoded><![CDATA[<p>So this one is done <a href="http://byatool.com/lessons/jquery-validator-adding-a-custom-method/#comment-143411747">on request</a> and because I am a kind of merciful god I will grant this request.</p>
<p>For those bullet point programmers:</p>
<ul>
<li>The working demo can be <a href="http://demo.byatool.com/CheckBoxValidation/checkboxValidation.html">found here</a></li>
<li>The code can be  <a href="http://demo.byatool.com/checkBoxValidation.zip">easily downloaded</a></li>
</ul>
<p>Now when I say validation, I mean the <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">validation plugin.</a> and this example is built using <a href="http://byatool.com/lessons/jquery-validator-adding-a-custom-method/">concepts in this post.</a></p>
<p>Here&#8217;s the markup:</p>
<pre>
&lt;<span style="color: #003366;">form</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"formCheckBoxValidation"</span> <span style="color: #ff0000;">method</span>=<span style="color: #800080;">"post"</span> <span style="color: #ff0000;">action</span>=<span style="color: #800080;">"checkboxValidation.html"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"One"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"Two"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"Three"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"Four"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxList"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"Five"</span>&gt;
	&lt;<span style="color: #003366;">br</span> /&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"submit"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"buttonCheckBoxValidation"</span>&gt;
&lt;/<span style="color: #003366;">form</span>&gt;
&lt;<span style="color: #003366;">div</span>&gt;
	&lt;<span style="color: #003366;">div</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"divError"</span> name=<span style="color: #800080;">"divError"</span> style=<span style="color: #800080;">"display:none;"</span>&gt;&lt;/<span style="color: #003366;">div</span>&gt;
&lt;/<span style="color: #003366;">div</span>&gt;

&lt;<span style="color: #003366;">form</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"formCheckBoxValidationDifferentName"</span> <span style="color: #ff0000;">method</span>=<span style="color: #800080;">"post"</span> <span style="color: #ff0000;">action</span>=<span style="color: #800080;">"checkboxValidation.html"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxListOne"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxListOne"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"One"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxListTwo"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxListTwo"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"Two"</span>&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"checkbox"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"checkBoxListThree"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"checkBoxListThree"</span> <span style="color: #ff0000;">value</span>=<span style="color: #800080;">"Three"</span>&gt;
	&lt;<span style="color: #003366;">br</span> /&gt;
	&lt;<span style="color: #003366;">input</span> <span style="color: #ff0000;">type</span>=<span style="color: #800080;">"submit"</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"buttonCheckBoxValidationDifferentName"</span>&gt;
&lt;/<span style="color: #003366;">form</span>&gt;
&lt;<span style="color: #003366;">div</span>&gt;
	&lt;<span style="color: #003366;">div</span> <span style="color: #ff0000;">id</span>=<span style="color: #800080;">"divErrorDifferentName"</span> <span style="color: #ff0000;">name</span>=<span style="color: #800080;">"divErrorDifferentName"</span> <span style="color: #ff0000;">style</span>=<span style="color: #800080;">"display:none;"</span>&gt;&lt;/<span style="color: #003366;">div</span>&gt;
&lt;/<span style="color: #003366;">div</span>&gt;
</pre>
<p>For this example I&#8217;m actually presenting two examples(Say &#8216;example&#8217; again, I dare you, I double dare you m&#8212;erf&#8212;er, say &#8216;example&#8217;Â one more God d&#8211;n time!): If the checkboxes are linked by id and if the checkboxes are not linked at all.  There is actually a difference.  You see, if they share the same id, the required method can be used since it will treat them all as the same element and therefore if even on is checked, there is a value.  Otherwise, you have to check all the checkboxes to see if at least one is checked. (Yeah, that made total sense.)</p>
<p>Here&#8217;s the check checkboxes method:</p>
<pre
<span style="color: #008000;">//Add a method to the validator that checks to see if at least one of the
//  three checkboxes specified are checked.</span>
jQuery.validator.addMethod(<span style="color: #800000;">'atLeastOneChecked'</span>, <span style="color: #0000ff;">function</span>(value, element) {
	<span style="color: #0000ff;">var</span> checkedCount = 0;

	if (jQuery(<span style="color: #800000;">'#checkBoxListOne'</span>).is(<span style="color: #800000;">':checked'</span>)){
		checkedCount += 1;
	}

	if (jQuery(<span style="color: #800000;">'#checkBoxListTwo'</span>).is(<span style="color: #800000;">':checked'</span>)){
		checkedCount += 1;
	}

	if (jQuery(<span style="color: #800000;">'#checkBoxListThree'</span>).is(<span style="color: #800000;">':checked'</span>)){
		checkedCount += 1;
	}

	return checkedCount &gt; 0;
});
</pre>
<p>Oooooh baby.</p>
<p>Now for setting up the validation:</p>
<pre>
<span style="color: #008000;">//This is for the first checkbox area where every checkbox has the same id causing them
//  to be a group and therefore the default required works.</span>
<span style="color: #0000ff;">var</span> validationRules = <span style="color: #0000ff;">new</span> <span style="color: #008080;">Object</span>();
validationRules[<span style="color: #800000;">'checkBoxList'</span>] = {required:<span style="color: #0000ff;">true</span>};

<span style="color: #0000ff;">var</span> validationMessages = <span style="color: #0000ff;">new</span> <span style="color: #008080;">Object</span>();
validationMessages[<span style="color: #800000;">'checkBoxList'</span>] = {required:<span style="color: #800000;">'at least one has be checked.'</span>};

jQuery(<span style="color: #800000;">'#formCheckBoxValidation'</span>).validate({
	errorLabelContainer: <span style="color: #800000;">'#divError'</span>,
	wrapper: <span style="color: #800000;">'div'</span>,
	rules: validationRules,
	messages: validationMessages,
	onfocusout: <span style="color: #0000ff;">false</span>,
	onkeyup: <span style="color: #0000ff;">false</span>,
	submitHandler: <span style="color: #0000ff;">function</span> (label) {
		alert(<span style="color: #800000;">'hooray')</span>;
	}
});

<span style="color: #008000;">//This is for the second checkbox area where every checkbox has a different name
//  and therefore the atLeastOneChecked method must be used.</span><span style="color: #008000;">
</span>validationRules = <span style="color: #0000ff;">new</span> <span style="color: #008080;">Object</span>();
validationRules[<span style="color: #800000;">'checkBoxListOne'</span>] = {atLeastOneChecked:true};

validationMessages = <span style="color: #0000ff;">new</span> <span style="color: #008080;">Object</span>();
validationMessages[<span style="color: #800000;">'checkBoxListOne'</span>] = {atLeastOneChecked:<span style="color: #800000;">'at least one has be checked.'</span>};

jQuery(<span style="color: #800000;">'#formCheckBoxValidationDifferentName'</span>).validate({
	errorLabelContainer: <span style="color: #800000;">'#divErrorDifferentName'</span>,
	wrapper: <span style="color: #800000;">'div'</span>,
	rules: validationRules,
	messages: validationMessages,
	onfocusout: <span style="color: #0000ff;">false</span>,
	onkeyup: <span style="color: #0000ff;">false</span>,
	submitHandler: <span style="color: #0000ff;">function</span> (label) {
		alert(<span style="color: #800000;">'hooray'</span>);
	}
});
</pre>
<p>In the words of Q-Bert: @#$% yeah!</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/lessons/jquery-validation-with-multiple-checkboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Validator: Adding a Custom Method</title>
		<link>http://byatool.com/lessons/jquery-validator-adding-a-custom-method/</link>
		<comments>http://byatool.com/lessons/jquery-validator-adding-a-custom-method/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 18:09:28 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery Validator]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1879</guid>
		<description><![CDATA[File this one under &#8220;Posted to take less time to find the answer&#8221;: If you&#8217;re using jQuery Validator and the built in validation methods just aren&#8217;t cutting, there&#8217;s a way you can add your own method to the validator itself. For this example let&#8217;s start some pretend time. Uhg I said pretend time not f&#8211;ked [...]]]></description>
			<content:encoded><![CDATA[<p>File this one under  &#8220;Posted to take less time to find the answer&#8221;:</p>
<p>If you&#8217;re using jQuery Validator and the built in validation methods just aren&#8217;t cutting, there&#8217;s a way you can add your own method to the validator itself.  For this example let&#8217;s start some pretend time.  Uhg I said pretend time not f&#8211;ked up fantasy time&#8230; Really, a horse?  Really?</p>
<p>Now that we have that clear: Let&#8217;s pretend you have a form with three textboxes and you want to make sure one and only one is filled out.  This doesn&#8217;t exactly fit the built in methods.  Now you could try using the &#8220;required&#8221; method and replace it with a delegate.  Could do that, but it &#8216;sÂ  actually trickier than it sounds due to how required method actually works.Â   So what&#8217;s an easier way?  Just add a method to the validator:</p>
<pre>    jQuery.validator.addMethod(<span style="color: #ff0000;">'correctCountFilled'</span>, <span style="color: #0000ff;">function</span>(value, element) {
        <span style="color: #0000ff;">var</span> fullCount = 0;
        <span style="color: #0000ff;">if</span>(jQuery(<span style="color: #ff0000;">'#someTextBox1'</span>).val().length &gt; 0){
            fullCount +=1;
        }

        <span style="color: #0000ff;">if</span>(jQuery(<span style="color: #ff0000;">'#someTextBox2'</span>).val().length &gt; 0){
            fullCount +=1;
        }

        <span style="color: #0000ff;">if</span>(jQuery(<span style="color: #ff0000;">'#someTextBox3'</span>).val().length &gt; 0){
            fullCount +=1;
        }

        <span style="color: #0000ff;">return</span> fullCount == 1;
    });
</pre>
<p>Then the call is done lika dis:</p>
<pre>  ...

  rules: {
            someTextBox1: {
                correctCountFilled:  <span style="color: #0000ff;">true </span> <span style="color: #339966;">//This is the name of the method added and what it expects to come back when called to be valid.</span>
            }
        },
  messages: {
            someTextBox1: {
                correctCountFilled: <span style="color: #ff0000;">'Some error message like pointing out how yours is a superior intellect.'</span>
            }
        },
  ...
</pre>
<p>As you can see, the method returns false if all are empty or more than one is filled in.  The method call on the validator expects &#8220;true&#8221; to be valid, so anything but one textbox being filled in will trigger the error message.  Fairly easy, huh?  Now go forth, be fruitful, and don&#8217;t multiply by mistake.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/lessons/jquery-validator-adding-a-custom-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC2, Dynamic Models, Json, and Javascript</title>
		<link>http://byatool.com/mvc/asp-net-mvc2-dynamic-models-json-and-javascript/</link>
		<comments>http://byatool.com/mvc/asp-net-mvc2-dynamic-models-json-and-javascript/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 00:59:01 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ExpandoObject]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[MVC 2]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1830</guid>
		<description><![CDATA[Ok so one thing I fell into while using the dynamic keyword as a model, was an issue with the dynamic model being parsed into json and then back again into javasript using jQuery. Silly me, I thought that the dynamic model would represent itself like any other object, but it turns out the dynamic [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so one thing I fell into <a href="http://byatool.com/pontification/asp-net-mvc-2c-4-dynamic-model-and-should-you-use-it/">while using the dynamic keyword as a model</a>, was an issue with the dynamic model being parsed into json and then back again into javasript using jQuery.  Silly me, I thought that the dynamic model would represent itself like any other object, but it turns out the dynamic object is actually a dictionary with a key value pair.  Now I&#8217;m not going to harp on that since I think that&#8217;s kind of how Python does it (And javascript for that matter), but I did want this:</p>
<pre><span style="color: #0000ff;">function</span> doSomething(result) {
  <span style="color: #0000ff;">if</span>(result.Success){
    alert(result.Value.UserName);
  }
}</pre>
<p>Where the result value was:</p>
<pre>...  <span style="color: #008000;">//Other junk</span>
<span style="color: #0000ff;">dynamic</span> returnModel = <span style="color: #0000ff;">new</span> <span style="color: #008080;">ExpandoObject</span>();
returnModel.UserName = _state.CurrentUser.UserName;
result.Value = returnModel;
...  <span style="color: #008000;">//set the data on a jSonResult to that result above and return.</span></pre>
<p>But what I got for Value was a dictionary:</p>
<pre>  result.Value[0].Key  "UserName"
  result.Value[0].Value  "test@test.com"</pre>
<p>As you can guess, using the javascript from above won&#8217;t work.  However, there is a way to run the above javascript.</p>
<pre>    <span style="color: #0000ff;">var</span> convertedValue = <span style="color: #0000ff;">new</span> Object;

    <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">var</span> i = 0; i &lt; result.Value.length; i++){
      convertedValue [result.Value[i].Key] = result.Value[i].Value;
    }</pre>
<p>You see with javascript, like the dynamic object, the objects not only respond to a direct assignment like a property, but can also be manipulated like a dictionary.  Where does that code above get me?  Well simple, I can now do:</p>
<pre>  alert(convertedValue.UserName);</pre>
<p>Yeah its not perfect and I have to think there will be some way for a better json translation, but for now this is gold.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/mvc/asp-net-mvc2-dynamic-models-json-and-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Validate Date/Check If Is Date</title>
		<link>http://byatool.com/ui/jquery-validate-datecheck-if-is-date/</link>
		<comments>http://byatool.com/ui/jquery-validate-datecheck-if-is-date/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 18:04:31 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1794</guid>
		<description><![CDATA[Far as I can tell, and that&#8217;s pretty far even though I do wonder if you can actually measure telling in distance, there isn&#8217;t a method directly used for validating a date in jquery. I find this rather odd. Not odd like how people keep watching Uwe Bol movies, more like odd that no one [...]]]></description>
			<content:encoded><![CDATA[<p>Far as I can tell, and that&#8217;s pretty far even though I do wonder if you can actually measure telling in distance, there isn&#8217;t a method directly used for validating a date in jquery. I find this rather odd. Not odd like how people keep watching Uwe Bol movies, more like odd that no one has tried to make a time machine to prevent them from ever appearing.</p>
<p>Anyways, bad movies&#8230; horrible movies&#8230; worst movies of all time aside, there is a date checking method, just not directly in jquery. It&#8217;s actually in the jquery.ui.datepicker.js file which is <a href="http://jqueryui.com/download">part of the UI files.</a> Basically I grabbed that file and used the parseDate method on it coupled with a try catch. After all, a failure in the parseDate method throws an exception, and we don&#8217;t like those. No we don&#8217;t. (Which begs the question as why it throws an exception instead of just returning a null date.)</p>
<pre><span style="color: #0000ff;">function</span> isValidDate(controlName, format){
    <span style="color: #0000ff;">var</span> isValid = <span style="color: #0000ff;">true</span>;

    <span style="color: #0000ff;">try</span>{
        jQuery.datepicker.parseDate(format, jQuery(<span style="color: #ff0000;">'#'</span> + controlName).val(), <span style="color: #0000ff;">null</span>);
    }
    <span style="color: #0000ff;">catch</span>(error){
        isValid = false;
    }

    <span style="color: #0000ff;">return</span> isValid;
}</pre>
<p>Very simple, and it works. You could ask why I didn&#8217;t just roll my own date method, and then I would ask you how ambitious do you think I am? Then you would punch me because I answered your question with a question like a complete tool bag. Then I would cry. And THEN I would answer your original question. Fact is, I trust that the method created for the DatePicker is in fact well tested, otherwise the whole jquery thing just isn&#8217;t worth trusting seeing as it&#8217;s a part of their core library. And that I just refuse to believe.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-validate-datecheck-if-is-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Find a Form Action Using Jquery</title>
		<link>http://byatool.com/ui/jquery-find-a-form-action-using-jquery/</link>
		<comments>http://byatool.com/ui/jquery-find-a-form-action-using-jquery/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 16:59:04 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1699</guid>
		<description><![CDATA[This is pretty useful for people trying to pass in a generated action to a javascript file.Â  Eh? SKIP IF YOU DON&#8217;T CARE ABOUT A REASON FOR USING THIS: Say you are using the jQuery post method to send things back to the server but all the code for that is in a seperate javascript [...]]]></description>
			<content:encoded><![CDATA[<p>This is pretty useful for people trying to pass in a generated action to a javascript file.Â  Eh?</p>
<h1><span style="color: #ff0000;">SKIP IF YOU DON&#8217;T CARE ABOUT A REASON FOR USING THIS:</span></h1>
<p>Say you are using the jQuery post method to send things back to the server but all the code for that is in a seperate javascript file.Â  Well you can&#8217;t really do this:</p>
<pre>jQuery.ajax({
      type:<span style="color: #800000;">'POST'</span>,
      url: <span style="color: #ff9900;">&lt;%=</span> someMethodForCreatingAUrl(<span style="color: #ff0000;">'controller'</span>, <span style="color: #ff0000;">'action'</span>) <span style="color: #ff9900;">%&gt;</span>,
      dataType:'json',
      data:{
        email: user.userName,
        password: user.password
      },
      success: function(result){
        onSuccess(result);
      },
      error:function (xhr, ajaxOptions, thrownError){
        alert(xhr.status);
      }
    });</pre>
<p>if that is in the javascript file.</p>
<p>What you can do is this on the html file:</p>
<pre>  &lt;<span style="color: #800000;">form</span> <span style="color: #0000ff;">id=</span><span style="color: #ff0000;">"formCreateUser"</span> <span style="color: #0000ff;">name=</span><span style="color: #ff0000;">"formCreateUser"</span> <span style="color: #0000ff;">method=</span><span style="color: #ff0000;">"post"</span> <span style="color: #0000ff;">action=</span>"${someMethodForCreatingAUrl('controller', 'action')}"&gt;</pre>
<p>And in the javascript file:</p>
<h1><span style="color: #ff0000;">ANSWER:</span></h1>
<pre>  <span style="color: #0000ff;">var</span> formAction = jQuery(ELEMENT_LOGIN_FORM).attr(<span style="color: #ff0000;">'action'</span>);</pre>
<p>And there you go. You have the action.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-find-a-form-action-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ByATool.com gets a shiny new tool!</title>
		<link>http://byatool.com/writing/byatool-com-gets-a-shiny-new-tool/</link>
		<comments>http://byatool.com/writing/byatool-com-gets-a-shiny-new-tool/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 14:03:01 +0000</pubDate>
		<dc:creator>Andre</dc:creator>
				<category><![CDATA[Website News]]></category>
		<category><![CDATA[Writing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1287</guid>
		<description><![CDATA[A while back, we put up an offer to write for our blog.Â  Only one has risen to the top as someone having both the technical know-how and the razor sharp wit required to write on a site such as this. ByATool.com Readers&#8230; Amy. Amy&#8230; ByATool.com Readers. Amy is a magnificent geek and almost 10 [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, we put up an offer to write for our blog.Â  Only one has risen to the top as someone having both the technical know-how and the razor sharp wit required to write on a site such as this.</p>
<p>ByATool.com Readers&#8230; Amy.</p>
<p>Amy&#8230; ByATool.com Readers.</p>
<p>Amy is a magnificent geek and almost 10 year veteran of server administration  and software development. She has worked at IBM, Concurrent Technologies  Corporation, and University of Pittsburgh Medical Center.  Currently,  she is doing custom SharePoint development connected with Team  Foundation Server and the ASP.NET MVC framework development using the Entity  Framework, C#, and jQuery.  She is currently living in Pittsburgh and  not happy at all about commuting into a city with 3 rivers because of  the many bridges and no serious commuter subway systems&#8230; Who plans  this stuff?</p>
<p>Welcome Amy!</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/writing/byatool-com-gets-a-shiny-new-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Child IFrame Page Interacting with Parent Page&#8230; Yeah I went there.</title>
		<link>http://byatool.com/lessons/child-iframe-page-interacting-with-parent-page-yeah-i-went-there/</link>
		<comments>http://byatool.com/lessons/child-iframe-page-interacting-with-parent-page-yeah-i-went-there/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 20:07:54 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1241</guid>
		<description><![CDATA[Example here. File this under &#8220;Why?&#8221; but I wanted to see if a child could talk to a parent and then receive information back from the parent to update itself with. As usual, my lack of intelligent wording probably has you scratching your head&#8230; if you do that. Personally I don&#8217;t get that expression as [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.byatool.com/Hosted/LiveDemos/JavascriptIframeDelegate/Parent.htm">Example here.</a></p>
<p>File this under &#8220;Why?&#8221; but I wanted to see if a child could talk to a parent and then receive information back from the parent to update itself with.  As usual, my lack of intelligent wording probably has you scratching your head&#8230; if you do that.  Personally I don&#8217;t get that expression as when I&#8217;m confused I more than likely will grab a jar of peanut butter and start lathering up with it, but to each his own.</p>
<p>So here&#8217;s the idea, and this post is only the start.</p>
<p>You have a parent page, Parent.htm, with an iframe and you want the parent to do something and alert the child that something happened.  For now, it&#8217;s actually really simple.</p>
<p>On the parent I have a method:</p>
<pre>  <span style="color: #0000ff;">function</span> callMethod(text, methodDelgate) {
    <span style="color: #0000ff;">if</span> (methodDelgate != <span style="color: #0000ff;">null</span>) {
      methodDelgate(text);
    }
  }
</pre>
<p>And this simple markup:</p>
<pre>  &lt;iframe id="myFrame" src="Child.htm"&gt;&lt;/iframe&gt;
</pre>
<p>Wow huh?  Well on the child I have this:</p>
<pre>  <span style="color: #0000ff;">function</span> callParent(text) {
    <span style="color: #0000ff;">if</span> (top.callMethod != <span style="color: #0000ff;">null</span>) {
	  top.callMethod(text, changeText);
    }
  }
</pre>
<p>This is easy.  If the parent has the method, send the text through and a method to call when finished.  What is this method?  Well its:</p>
<pre>  <span style="color: #0000ff;">function </span>changeText(text) {
    jQuery(<span style="color: #800000;">'#returnText'</span>).text(text);
  }
</pre>
<p>Which simply sets the text on some div to show it actually worked.</p>
<p>What happens when I click a button that calls callParent?  It talks to the parent, the parent calls the passed in method, and the child updates itself.</p>
<p>Not sure this is rocket science, but there will be more on it as I add in the idea of a dynamically created pop up on the parent being used by the child.  Until then, try not to be yourself.  You embarrass your mother.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/lessons/child-iframe-page-interacting-with-parent-page-yeah-i-went-there/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the jQuery DatePicker to Work With jQuery Modal Dialog</title>
		<link>http://byatool.com/lessons/get-the-jquery-datepicker-to-work-with-jquery-modal-dialog/</link>
		<comments>http://byatool.com/lessons/get-the-jquery-datepicker-to-work-with-jquery-modal-dialog/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 19:35:41 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1231</guid>
		<description><![CDATA[Being that I am the man, I thought I would share this little thingy with you because&#8230; well I&#8217;m the man. So here&#8217;s the issue:Â  You have a date picker, a modal dialog, and you can&#8217;t see the calendar when you click on the icon and/or textbox. First thought, &#8216;WHY DOES THIS HAPPEN TO ME???!?!&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>Being that I am the man, I thought I would share this little thingy with you because&#8230; well I&#8217;m the man.</p>
<p>So here&#8217;s the issue:Â  You have a date picker, a modal dialog, and you can&#8217;t see the calendar when you click on the icon and/or textbox.  First thought, &#8216;WHY DOES THIS HAPPEN TO ME???!?!&#8217;  Second though, &#8216;I wonder if that tool knows how to get past this.&#8217;  Good news!  I do.  Turns out it has to do with the z-index.  The modal dialog by default has a z-index of 1000ish when showing. (And any modal dialog &#8220;above that&#8221; will increase it&#8217;s z-index to match.)  If the calendar isn&#8217;t higher than that, no go.  </p>
<p>Now you might be using the jquery styles from <a href="http://jqueryui.com/themeroller/"> the jquery site</a> and might be putting your through your keyboard thinking about having to deal with that mess.  However, it&#8217;s actually a simple fix in there&#8230; there being the ui.datepicker.css file.</p>
<pre>
  .ui-datepicker { width: 17em; padding: .2em .2em 0;<strong> z-index:9000</strong>; }
</pre>
<p>And there you have it.  Now the calendar will show up in front of anything lower than 9000, and as everyone knows: Anything over 9000 is impossible.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/lessons/get-the-jquery-datepicker-to-work-with-jquery-modal-dialog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Modal Dialog : Hide That Stupid X Button / Windows Close Button</title>
		<link>http://byatool.com/ui/jquery-modal-dialog-hide-that-stupid-x-button-windows-close-button/</link>
		<comments>http://byatool.com/ui/jquery-modal-dialog-hide-that-stupid-x-button-windows-close-button/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 16:05:18 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Modal Dialog]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1213</guid>
		<description><![CDATA[This is quick one, so hold on to your&#8230; whatever. Want to get rid of that X at the top right of the modal &#8220;Control&#8221;? Well here it is: (The bold part, moron) jQuery('#WaitingDiv').dialog({ autoOpen: false, bgiframe: false, height: 150, width: 200, modal: true, open: function(event, ui) { jQuery('.ui-dialog-titlebar-close').hide(); } }); And that&#8217;s really it. [...]]]></description>
			<content:encoded><![CDATA[<p>This is quick one, so hold on to your&#8230; whatever.</p>
<p>Want to get rid of that X at the top right of the modal &#8220;Control&#8221;?  Well here it is:  (The bold part, moron)</p>
<pre>     jQuery(<span style="color: #800000;">'#WaitingDiv'</span>).dialog({
          autoOpen: false,
          bgiframe: false,
          height: 150,
          width: 200,
          modal: true,
         <strong> open: function(event, ui) { jQuery(<span style="color: #800000;">'.ui-dialog-titlebar-close'</span>).hide();</strong> }
        });
</pre>
<p>And that&#8217;s really it.  Just thought I&#8217;d pass that on to you, the consumer.</p>
<p>On a side note, the big movie thing is the <a href=" http://www.huffingtonpost.com/2010/01/11/spider-man-4-off-spider-m_n_419264.html">canceling of Spiderman 4 or at least going in a new direction</a>.  As much as I don&#8217;t care, it might lead to my dream come true:</p>
<p>A spiderman movie based on the SNES classic: Spider-Man &amp; Venom: Maximum Carnage.  Uwe Boll, are you out there?</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-modal-dialog-hide-that-stupid-x-button-windows-close-button/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>jQuery &#8211; Check All Checkboxes Toggle Method Thingy</title>
		<link>http://byatool.com/ui/jquery-check-all-checkboxes-toggle-method-thingy/</link>
		<comments>http://byatool.com/ui/jquery-check-all-checkboxes-toggle-method-thingy/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 23:20:11 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1203</guid>
		<description><![CDATA[So here&#8217;s a quick on for all you boys and girls&#8230; and anything else I might have missed. Say you want to check all check boxes in a grid or whatever, but you want it to toggle. So if if it&#8217;s time to check all, all get checked and then the next time the button [...]]]></description>
			<content:encoded><![CDATA[<p>So here&#8217;s a quick on for all you boys and girls&#8230; and anything else I might have missed.<br />
Say you want to check all check boxes in a grid or whatever, but you want it to toggle.  So if if it&#8217;s time to check all, all get checked and then the next time the button is clicked it will uncheck.  Now you could do this in three methods, maybe two but that&#8217;s why you&#8217;re a mouth breather.</p>
<p>Special people like me do it in one.</p>
<pre>    <span style="color: #0000ff;">function</span> toggleCheckboxes(buttonId, checkBoxNamePrefix, checked)
    {
      <span style="color: #008000;">//Get all checkboxes with the prefix name and check/uncheck</span>
      jQuery(<span style="color: #800000;">'[id*=' + checkBoxNamePrefix + ']'</span>).attr(<span style="color: #800000;">'checked'</span>, checked);

      <span style="color: #008000;">//remove any click handlers from the button</span>
      <span style="color: #008000;">//  Why?  Because jQuery(buttonId).click() will just add another handler</span>
      jQuery(buttonId).unbind(<span style="color: #800000;">'click'</span>); 

      <span style="color: #008000;">//Add the new click handler</span>
      jQuery(buttonId).click(
        <span style="color: #0000ff;">function</span>() {
          toggleCheckboxes(buttonId, checkBoxNamePrefix, !checked);
        }
      );
    }</pre>
<p>And POW!  What?  You want to know how to use it?  Fine, but only because I&#8217;m nice.</p>
<pre>   jQuery(<span style="color: #800000;">'#buttonName'</span>).click(
     <span style="color: #0000ff;">function</span>() {
       toggleCheckboxes(<span style="color: #800000;">'#buttonName'</span>,<span style="color: #800000;"> 'someCheckBoxName'</span>, <span style="color: #0000ff;">true</span>);
     }
   );</pre>
<p>And in case you were still wondering why I used .unbind and didn&#8217;t understand the comment, it&#8217;s because using just .click will add another handler to the button. So next click you will get both check and uncheck all.  Kind of hurts the effectiveness.</p>
<p>And there you have it.  Once again I have filled your life with meaning.  Couldn&#8217;t be easier.  Or maybe it could but that&#8217;s not my problem now is it?  Go back to doing something useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-check-all-checkboxes-toggle-method-thingy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Validation: Adding Errors to the Error Containter&#8230; With Love!</title>
		<link>http://byatool.com/lessons/jquery-validation-adding-errors-to-the-error-containter-with-love/</link>
		<comments>http://byatool.com/lessons/jquery-validation-adding-errors-to-the-error-containter-with-love/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 21:28:49 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1178</guid>
		<description><![CDATA[Hello again, my wonderful audience, I have something great and fun planned for this post. If you read this post you might have been left wondering how to add custom messages to the error holder. It&#8217;s ok if you did, there&#8217;s nothing wrong with being confused all the time. It&#8217;s what makes you so adorable. [...]]]></description>
			<content:encoded><![CDATA[<pre><img src="http://www.iheartvector.com/wp-content/vector/hearts.png" alt="" /></pre>
<p><span  title="Please send help, the Board of Directors is forcing me to be nice!">Hello again, my wonderful audience, I have something great and fun planned for this post. If you read <a href="http://byatool.com/lessons/jquery-validation-how-to-use-to-get-rid-of-even-the-toughest-stains/">this post</a> you might have been left wondering how to add custom messages to the error holder. It&#8217;s ok if you did, there&#8217;s nothing wrong with being confused all the time. It&#8217;s what makes you so adorable.</span></p>
<p><span title="I really don't mean the last part.">Say you have a form like this, and if you don&#8217;t I cry endlessly for your loss. My heart goes out to you.</span></p>
<pre>&lt;<span style="color: #800000;">form</span> <span style="color: #0000ff;">id=</span><span style="color: #ff0000;">"ILoveEverythingForm"</span>&gt;
    &lt;<span style="color: #800000;">div</span> <span style="color: #0000ff;">id=</span><span style="color: #ff0000;">"NotSoNiceThingsDiv"</span> <span style="color: #0000ff;">style</span><span style="color: #0000ff;">=</span><span style="color: #ff0000;">"display:none;"</span>&gt;&lt;/<span style="color: #800000;">div</span>&gt;
	...
&lt;/<span style="color: #800000;">form</span>&gt;</pre>
<p><span title="This is the cheesiest piece of...">As you can see, there is an error div to hold mean things that we have to print out because the system just doesn&#8217;t like the user. As we both know, the user can&#8217;t help but be dumb. It&#8217;s just in his cute little nature. And that nature is just so darned cute.</span></p>
<p><span title="Uhg, this really sucks.">Now let&#8217;s assume that you have something that sent back a bunch of mean messages when you tried to validate server side after all the cute client side validation was done. You might have a method to take in those jerk face messages. How do you display them in the bad place?</span></p>
<pre>  <span style="color: #0000ff;">function</span> updateErrorDivContentWithLove(messages)
  {
    <span style="color: #0000ff;">if</span>(messages.length &gt; 0)
    {
      <span style="color: #0000ff;">var</span> validator = jQuery(<span style="color: #800000;">'#ILoveEverythingForm'</span>).validate();

      <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">var</span> loopCounter = 0; loopCounter &lt; messages.length; loopCounter ++)
      {
        validator.showErrors
        (
          {
             <span style="color: #800000;">'SomeWonderfulElementName'</span> : messages[loopCounter].Message
          }
        );
      }
    }
  }</pre>
<p><span title="I wish I could stab my eyes right now...">Awwww kitties!</span></p>
<pre>  <img src="http://www.dailypets.co.uk/wp-content/uploads/2007/06/kittens-cups.jpg" alt="" /></pre>
<p><span title="I am losing mad rep on this.">Only thing that may seem odd (And if it doesn&#8217;t, don&#8217;t worry you are still very special and loved in this world):</span></p>
<pre>  'SomeElementName' : messages[loopCounter].Message</pre>
<p><span title="Oh for f--ks sake...">Not sure what element really needs to be here, basically anything in the form with a name tag. So if you&#8217;re good like I know you are, you have at least one element in that little old form with a name property set. I would say that this is pretty useless in situations where all the errors are shown in one div, as opposed to right next to the element, but that would be mean and I don&#8217;t do that.</span></p>
<p><span title="I swear I'm not really a nice person, please believe me.">Now I know you wanted something special from this post so I just wanted you to know that even though most of the world considers you hideous, I say you should be proud of being hideous because it makes you who you are. A unique miracle that only really has issues with dogs and small children. Embrace yourself in whatever way you take that!</span></p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/lessons/jquery-validation-adding-errors-to-the-error-containter-with-love/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Grab Bag &#8211; Whole bunch of jQuery Functionality</title>
		<link>http://byatool.com/ui/jquery-grab-bag-whole-bunch-of-jquery-functionality/</link>
		<comments>http://byatool.com/ui/jquery-grab-bag-whole-bunch-of-jquery-functionality/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 21:06:32 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1125</guid>
		<description><![CDATA[You could look at this post as a self serving block that I will use to save stuff I don&#8217;t want to remember later. Or you could see it as a knowledge transfer that you the reader can learn from because I am a generous and giving tool. Whatever, I really don&#8217;t care. I won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>You could look at this post as a self serving block that I will use to save stuff I don&#8217;t want to remember later.</p>
<p>Or you could see it as a knowledge transfer that you the reader can learn from because I am a generous and giving tool.</p>
<p>Whatever, I really don&#8217;t care.  I won&#8217;t sleep any differently.  I just don&#8217;t feel like making 1000 posts of jquery stupidity.</p>
<p>I&#8217;ll add more as I come across them.</p>
<h2>Checkbox</h2>
<p><strong>How To Check a CheckBox</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#CheckBoxId'</span>).attr(<span style="color: #800000;">'checked'</span>, <span style="color: #0000ff;">false</span>);</pre>
<p><strong>How To Know if a Checkbox is Checked</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#CheckBoxId'</span>).is(<span style="color: #800000;">':checked'</span>)</pre>
<p><strong>How To Find a Bunch of Like Named Checkboxes that are Checked</strong></p>
<pre>  jQuery(<span style="color: #800000;">'[id*=someCheckBox_]:checked'</span>);</pre>
<h2>Drop Down Lists</h2>
<p><strong>How to Add an Item/Option to a Drop Down List</strong></p>
<pre> jQuery(<span style="color: #800000;">'#DropDownListId'</span>).append(jQuery(<span style="color: #800000;">'&lt;option&gt;'</span>).val(1).html(<span style="color: #800000;">"SomeText"</span>));</pre>
<p>Odd Note:  Apparently jquery is smart enough to set the attributes on the option AND close the option with &lt;/option&gt;</p>
<p><strong>How to Remove an Item/Option from a Drop Down List</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#DropDownListId option[value=\'3\']'</span>).remove();</pre>
<p><strong>How to Sort a Drop Down List by Option Text</strong></p>
<pre>  <span style="color: #0000ff;">var</span> sortedList = jQuery(<span style="color: #800000;">'#someDropDownList option'</span>).sort(
    <span style="color: #0000ff;">function</span> (first, second) {
      <span style="color: #0000ff;">return</span> first.text == second.text ? 0 : first.text &lt; second.text ? -1 : 1;
    }
  );

  jQuery(<span style="color: #800000;">'#someDropDownList'</span>).html(sortedList);</pre>
<h2>Elements</h2>
<p><strong> How to Filter Out an Element in a List</strong></p>
<pre>  someElementList.filter(<span style="color: #800000;">'[id=someId]'</span>);</pre>
<p>Example:</p>
<pre><span style="color: #008000;">  //Uncheck all id like someId_ and check only where id = someId_1</span>
<span style="color: #0000ff;">  var</span> someElementList = someElement.children(<span style="color: #800000;">'[id*=someId_]'</span>);
  someElementList.attr(<span style="color: #800000;">'checked'</span>, <span style="color: #0000ff;">false</span>);
  someElementList.filter(<span style="color: #800000;">'[id=someId_1]'</span>).attr(<span style="color: #800000;">'checked'</span>, <span style="color: #0000ff;">true</span>);</pre>
<p><strong>How To Find an Element Based on a Like Name/Using Wildcards</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#SomeTable'</span>).children(<span style="color: #800000;">'tr[id*=SomeRowId]'</span>);</pre>
<p><strong>How To Know if a Something is Hidden</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#CheckBoxId'</span>).is(<span style="color: #800000;">':hidden'</span>)</pre>
<p>Possible Use:</p>
<pre> <span style="color: #0000ff;">function</span> showOrHide(element) {
    <span style="color: #0000ff;">if</span>(jQuery(element).is(<span style="color: #800000;">':hidden'</span>)) {
      jQuery(element).show();
    }
    <span style="color: #0000ff;">else</span> {
      jQuery(element).hide();
    }
  }</pre>
<p><strong>How to Disable an Input/Select</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#DropDownListId'</span>).attr(<span style="color: #800000;">'disabled'</span>, <span style="color: #800000;">'disabled'</span>);</pre>
<p><strong>How to Enable an Input/Select</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#DropDownListId'</span>).removeAttr(<span style="color: #800000;">'disabled'</span>);</pre>
<p><strong>How to Know if an Element Exists</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#ElementId'</span>).length &gt; 0</pre>
<p>Possible use:</p>
<pre>  <span style="color: #0000ff;">function</span> elementExists(elementId) {
    <span style="color: #0000ff;">return</span> jQuery(elementId).length &gt; 0;
  }</pre>
<h2>String</h2>
<p><strong>How To Remove the First Character from a String</strong></p>
<pre>  someString.substring(1, someString.length)</pre>
<h2>Tables</h2>
<p><strong>How to Add a Row to a Table</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#TableId &gt; tbody:last'</span>).append(<span style="color: #800000;">'&lt;tr&gt;...&lt;/tr&gt;'</span>)</pre>
<p><strong>How to Remove a Table Row</strong></p>
<pre>  jQuery(<span style="color: #800000;">'#TableId &gt; tbody:last'</span>).children(someSortOfRowId).remove();</pre>
<h2>Methods</h2>
<p><strong>How to Post With a Link</strong></p>
<pre>  <span style="color: #0000ff;">function</span> postToUrl(path, params)
  {
    <span style="color: #0000ff;">var</span> method = "post"; 

    <span style="color: #0000ff;">var</span> form = document.createElement(<span style="color: #800000;">"form"</span>);
    form.setAttribute(<span style="color: #800000;">"method"</span>, method);
    form.setAttribute(<span style="color: #800000;">"action"</span>, path);
    for(<span style="color: #0000ff;">var</span> key <span style="color: #0000ff;">in</span> params)
    {
        var hiddenField = document.createElement(<span style="color: #800000;">"input"</span>);
        hiddenField.setAttribute(<span style="color: #800000;">"type"</span>, <span style="color: #800000;">"hidden"</span>);
        hiddenField.setAttribute(<span style="color: #800000;">"name"</span>, key);
        hiddenField.setAttribute(<span style="color: #800000;">"value"</span>, params[key]);
        form.appendChild(hiddenField);
    }
    document.body.appendChild(form);    

    form.submit();
  }</pre>
<p>Use:</p>
<pre>&lt;a href="javascript:postToUrl('/SomeController/SomeAction/', { 'id', '1' })"&gt;link&lt;/a&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/jquery-grab-bag-whole-bunch-of-jquery-functionality/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Validation &#8211; How to Use to Get Rid Of Even The Toughest Stains</title>
		<link>http://byatool.com/lessons/jquery-validation-how-to-use-to-get-rid-of-even-the-toughest-stains/</link>
		<comments>http://byatool.com/lessons/jquery-validation-how-to-use-to-get-rid-of-even-the-toughest-stains/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 18:17:29 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Lessons]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1092</guid>
		<description><![CDATA[So you want to use jQuery validation, huh? What is it? Something that was added to the holy jquery site and is an easy way to validate input from users. Now this should in no way take over for server side validation, but it helps to at least catch a few things without having to [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to use jQuery validation, huh?</p>
<p>What is it?  Something that was added to the<a href="http://jquery.com/"> <strong>holy jquery site</strong></a> and is an easy way to validate input from users. Now this should in no way take over for server side validation, but it helps to at least catch a few things without having to send anything to the server.  So how do ya do it?</p>
<p>Well to start, you need some files:</p>
<p><a href="http://docs.jquery.com/Release:jQuery_1.3.2">jquery-1.3.2.js</a> and <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">jquery.validate.js</a>.</p>
<p>Now oddly enough the validation file isn&#8217;t hosted on the <a href="http://jquery.com/"> <strong>holy jquery site</strong></a> but <a href="http://docs.jquery.com/Plugins/Validation">how to use it is</a>.</p>
<p>Ok now you have the files, what&#8217;s next?  Well you need form, and <a href="http://byatool.com/hosted/LiveDemos/jQueryValidation/SimpleRequired.html">I can do that for you.</a></p>
<p>So basically it&#8217;s a simple form with one input that is required.</p>
<pre>jQuery(document).ready
    (
      <span style="color: #0000ff;">function</span>()
      {
        jQuery(<span style="color: #800000;">"#PrimaryForm"</span>).validate
        (
          {
            errorLabelContainer: <span style="color: #800000;">"#ErrorDiv"</span>,
            wrapper: <span style="color: #800000;">"div"</span>,
            rules:
            {
              FirstName :
              {
                required : <span style="color: #0000ff;">true</span>
              }
            },
            messages:
            {
              FirstName:
              {
                required : <span style="color: #800000;">'First Name is required.'</span>
              }
            },
            onfocusout : false,
            onkeyup: false,
            submitHandler: <span style="color: #0000ff;">function</span>(label)
            {
              postSubmit();
            }
          }
        );
      }</pre>
<pre>jQuery(<span style="color: #800000;">"#PrimaryForm"</span>).validate</pre>
<p>Real simple, just setting the validator to the primary form on the page.</p>
<pre> errorLabelContainer: <span style="color: #800000;">"#ErrorDiv"</span>,</pre>
<p>This sets the errors to show up in the ErrorDiv.  Now this is optional, as you can have it show the errors next to the FirstName text box but personally I think that looks horrible.  Setting up the ErrorDiv puts all the errors in one central location and allows for styling the actual div.</p>
<pre> rules:
 {
    FirstName :
    {
      required : <span style="color: #0000ff;">true</span>
    }
  },</pre>
<p>This matches an element with the id of FirstName to the required rule, meaning that FirstName is required.  Rocket science.</p>
<pre>  messages:
  {
    FirstName:
    {
       required : <span style="color: #800000;">'First Name is required.'</span>
    }
  },</pre>
<p>If you can&#8217;t figure this out, I hear circus is hiring for the &#8220;World&#8217;s Dumbest Person&#8221;.  You&#8217;ll fit in with Jub Jub the Dog Boy.</p>
<pre>  onfocusout : <span style="color: #0000ff;">false</span>,
  onkeyup: <span style="color: #0000ff;">false</span>,</pre>
<p>Basically this prevents the validation when leaving the textbox or on every key press.  This is just another preference.</p>
<pre>  submitHandler: <span style="color: #0000ff;">function</span>(label)
  {
    postSubmit();
  }</pre>
<p>If the submit is successful, call this method.</p>
<p><strong>But&#8230; BUT WHAT IF IT&#8217;S AN EMAIL?!??! WHAT WILL I DO???!?!?</strong></p>
<p>Well for one, stop being such a child.  <a href="http://byatool.com/hosted/LiveDemos/jQueryValidation/EmailRequired.html">And two, look here.</a></p>
<p>Some what different, as you can see it&#8217;s now email and there is one extra requirement in the rules:</p>
<pre>  rules:
  {
    EmailAddress :
    {
      email : <span style="color: #0000ff;">true</span>,
      required : <span style="color: #0000ff;">true</span>
    }
  },
  messages:
  {
    EmailAddress:
    {
      required : <span style="color: #800000;">'Yo, email fool.'</span>,
      email : <span style="color: #800000;">'So not an email address.'</span>
    },
  },</pre>
<p>See?  It has nice built in rule for email.  Simple.</p>
<p><strong>BUT WHAT IF I NEED A REGULAR EXPRESSION?!??! WHAT WILL I DO???!?!?</strong></p>
<p>I swear if you don&#8217;t stop that, I&#8217;m turning this post around and going home.</p>
<p><a href="http://byatool.com/hosted/LiveDemos/jQueryValidation/ZipCodeRequired.html">Fine here it is.</a></p>
<pre>  jQuery.validator.addMethod
  (
    <span style="color: #800000;">"isZipCode"</span>,
    <span style="color: #0000ff;">function</span>(value, element)
    {
      <span style="color: #0000ff;">return</span> value.match(<span style="color: #0000ff;">new</span> RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/));
    }
  );</pre>
<p>Just have to create a method and &#8220;add it&#8221; to the validator itself. And then there&#8217;s the use:</p>
<pre>  rules:
  {
    ZipCode :
    {
      required : <span style="color: #0000ff;">true</span>,
      isZipCode : <span style="color: #0000ff;">true</span>
    }
  },
  messages:
  {
    ZipCode:
    {
      required : <span style="color: #800000;">'For the love of me, enter a zip code!.'</span>,
      isZipCode : <span style="color: #800000;">'Serioulsy?  Do you know what a zip code is?'</span>
    },
  },</pre>
<p>Woo hoo right?</p>
<p>Don&#8217;t do it&#8230; Don&#8217;t you yell.</p>
<p><strong>But what if one input depends on another?</strong></p>
<p>Much better.  Well that&#8217;s not as hard as it may seem and <a href="http://byatool.com/hosted/LiveDemos/jQueryValidation/TwoRequired.html">here&#8217;s the example</a>.</p>
<pre>  rules:
  {
    InputB :
    {
      required :
      {
        depends : <span style="color: #0000ff;">function</span>(element) { <span style="color: #0000ff;">return</span> jQuery(<span style="color: #800000;">'#InputA'</span>).val() != <span style="color: #800000;">""</span> }
      }
    }
  },</pre>
<p>As you can see, you can change how the required method works by adding in a depends handler.  Works out pretty well.</p>
<p>Yes I will show you how to make sure two inputs match.  <a href="http://byatool.com/hosted/LiveDemos/jQueryValidation/EqualTo.html">I swear you ask for a lot.</a></p>
<pre>  rules:
  {
    Password :
    {
      equalTo : <span style="color: #800000;">"#ConfirmPassword"
</span>    },
  },</pre>
<p>Couldn&#8217;t be easier unless I wrote it out for you.  Wait, I did.</p>
<p>So here you&#8217;ve either learned a bit about jQuery validation or have just spent the last few minutes drooling uncontrollably. Either way, I&#8217;m done with this post and you&#8217;re left to do whatever it is you do, you sick f&#8212;.</p>
<p>Side note:  I haven&#8217;t actually been to <a href="http://www.htmlgoodies.com">Htmlgoodies</a> since eh college?  but wow did that place sell out.  How fitting that an introduction to html page now looks like it was designed by someone just starting out&#8230; in the 90s.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/lessons/jquery-validation-how-to-use-to-get-rid-of-even-the-toughest-stains/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC:  Quick Overview of Controller Structure</title>
		<link>http://byatool.com/pontification/asp-net-mvc-quick-overview-of-controller-structure/</link>
		<comments>http://byatool.com/pontification/asp-net-mvc-quick-overview-of-controller-structure/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 16:37:47 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Pontification]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=1012</guid>
		<description><![CDATA[Wow, that&#8217;s a mouthful far as titles go, but couldn&#8217;t think of a better way to say it. Now what I&#8217;m about to go through is the &#8220;system&#8221; I have found that works pretty well when it comes to structuring controllers knowing that there will be asynchronous operations. Why is that a big deal? Well [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, that&#8217;s a mouthful far as titles go, but couldn&#8217;t think of a better way to say it.  Now what I&#8217;m about to go through is the &#8220;system&#8221; I have found that works pretty well when it comes to structuring controllers knowing that there will be asynchronous operations.  Why is that a big deal?  Well where you put certain methods can depend on which controller actually owns the action.</p>
<p>When I started using MVC, I had some issues on figuring out how to build controllers so that they made sense from a structural point of view.  <a href="http://byatool.com/index.php/pontification/what-i-hate-about-programming/">I slightly touched on it</a> but I wanted to show where I progressed to in the vain hope that I can help prevent stumbling on your part.</p>
<p>One thing to be noted is the asynchronous part.  I&#8217;ve become a firm believer that MVC is pointless without asynchronous operations.  Why?  Simply put, you can use them or you can come up with some annoying post and redirect for any create, update, or delete operations.  If you&#8217;re going to do that, you might as well just be institutionalized because you are one masochistic mother f&#8212;er.  For everyone else in the happy world, go with something like jQuery that makes it real easy to perform said operations.</p>
<p>With the last paragraph in mind, the part I had trouble with the most was figuring out where the actions go.  You see, when I started using MVC, I grouped stuff in an ultra simple manor.  Say I have a site for handling pictures.  Well there would be a view controller that would have anything to do with viewing images and an admin controller that took care of the uploading, changing, deleting, ecting.  As you can imagine, this was not what you might call ideal.</p>
<p>Once I got a feeling for MVC and how it worked, I started having things a little more separated but still didn&#8217;t feel right.  I had actions for viewing a list of images on the image controller no matter if public or admin side which wasn&#8217;t really ideal to me since it kind of blurred what was public and what was restricted from a conceptual point of view.  </p>
<p>It wasn&#8217;t until I started thinking in terms of unit testing that it started to make more sense.  If I were creating controllers as if they were classes instead of pages like with WebForms, maybe it would work out better.  Seems real profound right?  Well it was at the time since I still had WebForms state of mind.  All of a sudden, it made way more sense on how the controllers should be set up.  In an odd way, the controllers almost became almost business layer like.  If I wanted to update an Image, there would be an Update method on the image controller responsible for taking in the changes, validating, and dealing with the entity objects.  Everything that had to do strictly with displaying information would be handled by a display controller like the before mentioned Admin controller.  So something like:</p>
<pre>
<img src="http://www.iamwebproject.com/PhotoView/Photo/ShowPhoto/14" alt="Controller Outline" />
</pre>
<p>As you can see, the Admin controller has something to show all users.  The User controller has the methods for things like updating, creating, and validation.  Basically anything that would change an image is on one controller.  Anything for showing it on the main section controller.  That is, a controller that embodies an overall concept like say an Admin section of a site or possibly a controller for viewing galleries.  </p>
<p>The sequence of events (bad word choice&#8230;) would be something like:</p>
<p>Open Admin/UserList/<br />
Admin controller uses User Entity to retrieve list<br />
Admin View shows User List<br />
User clicks delete button/link on Admin View<br />
Javascript/jQuery method invoked to send id to User/Delete<br />
User controller receives id<br />
User controller validates id to make sure it is valid<br />
User controller validates current user to see if allowed to delete<br />
User entity Delete method invoked by User Controller<br />
Result of Delete Method is returned by User Controller (JSon preferably)<br />
Admin View displays the result</p>
<p>Treating controllers like classes (and the use of anonymous actions) allows a very clean separation of actions resulting in a nice logical layout.  Beyond this, it also allows for a greater separation between controllers which means its possible to do multiple parts of the entire project in parallel.</p>
<p>Maybe this is just stating the obvious, something I&#8217;m pretty good at, but my hope was to give a quick over view of laying out controllers for those who are just starting out.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/pontification/asp-net-mvc-quick-overview-of-controller-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

