<?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>ITmeze &#187; jquery</title>
	<atom:link href="http://itmeze.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://itmeze.com</link>
	<description>IT world served like Cyprus meze</description>
	<lastBuildDate>Sat, 26 Jun 2010 00:15:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Tips for jQuery validation plugin</title>
		<link>http://itmeze.com/2009/08/tips-for-jquery-validation-plugin/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=tips-for-jquery-validation-plugin</link>
		<comments>http://itmeze.com/2009/08/tips-for-jquery-validation-plugin/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 12:18:41 +0000</pubDate>
		<dc:creator>ITmeze</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://itmeze.com/?p=80</guid>
		<description><![CDATA[Because I currently work with a couple of projects where I extensively use jQuery framework, together with it&#8217;s plugins I decided to write a post in which I can gather all of my ideas, tips that i have arrived during my work with this library.  I am a kind of guy that has a huge [...]


Related posts:<ol><li><a href='http://itmeze.com/2009/07/firefox-3-0-411-length-required-with-jquery/' rel='bookmark' title='Permanent Link: Firefox 3.0: 411 Length required with JQuery'>Firefox 3.0: 411 Length required with JQuery</a></li>
<li><a href='http://itmeze.com/2009/09/asp-net-mvc-1-0-issue-within-htmlhelper-getmodelstatevalue-method/' rel='bookmark' title='Permanent Link: ASP.NET MVC 1.0 issue within HtmlHelper.GetModelStateValue method'>ASP.NET MVC 1.0 issue within HtmlHelper.GetModelStateValue method</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-7051816622200841";
google_ad_slot = "0915606426";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<br />
Because I currently work with a couple of projects where I extensively use jQuery framework, together with it&#8217;s plugins I decided to write a post in which I can gather all of my ideas, tips that i have arrived during my work with this library.  I am a kind of guy that has a huge mess not only on his computer&#8217;s desktop but even within project files. It happens that when I arrive a problem, and I am sure I have figured it out in some other project but it usually takes me ages to dig through all of them to find even simplest solution. That is why I decided that I really need a place for all my tips and tricks, so I can find them easily.</p>
<p>This post focuses on jQuery Validation plugin, as i think this is the second thing i add to my project &#8211; after jQuery core file <img src='http://itmeze.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I will add more and more tips from time to time as soon as I find something worth to write down.</p>
<p>Ever worked with one of most popular <a title="jQuery Validation plugin" href="http://docs.jquery.com/Plugins/Validation" target="_blank">jQuery validation plugins</a>? This is extremely powerful and yet flexible plug-in that  makes form validation in javascript really easy.</p>
<p>Beside that fact that it already contains most popular validation rules, like checking field length, validating email or url format, it enables you to write your own &#8220;rule&#8221;.</p>
<h3>1. Adding new method</h3>
<p>Plugin supports method called &#8216;equalTo&#8217;. It is widely used &#8211; especially we request password confirmation. What is not supported is &#8216;notEqualTo&#8217; method. Not that popular but can be useful from time to time.  Let us say we have a field that needs to be different from other field, like new password has to be different than old password &#8211; maybe not the best choice but draws the picture.. OK, I guess recommended way to do that would be to add new method to jQuery validation plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  jQuery.<span style="color: #660066;">validator</span>.<span style="color: #660066;">addMethod</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;notEqualTo&quot;</span><span style="color: #339933;">,</span>
                             <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> element<span style="color: #339933;">,</span> param<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">optional</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> value <span style="color: #339933;">!=</span> $<span style="color: #009900;">&#40;</span>param<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                             <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;This has to be different...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#change-password-form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                rules<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #660066;">newPassword</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> notEqualTo<span style="color: #339933;">:</span><span style="color: #3366CC;">'#currentPassword'</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                messages<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> newPassword<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> notEqualTo<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;New password has to be different than old one&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>2. Preventing double form submission</h3>
<p>Another common issue every web developer arrives sooner or later is so called &#8216;double form submit&#8217;. Or going further on &#8216;multiple form submit&#8217;. It happens when user accidentally presses submit button couple of times, causing form to be send multiple times. If we have validation plugin for our form we can make use of submitHandler method to disable button after form is submitted.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#sample-form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                submitHandler<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">wasSent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">wasSent</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':submit'</span><span style="color: #339933;">,</span> form<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Please wait...'</span><span style="color: #009900;">&#41;</span>
                                          .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'disabled'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'disabled'</span><span style="color: #009900;">&#41;</span>
                                          .<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        form.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>3. Turning on/off validation under certain conditions</h3>
<p>It happens quite often that we require input in certain field only when some other element is selected. I just finished making web page that allows users to subscribe to newsletters on their request.  If user selects certain check-box &#8211; it means he want to subscribe and we require from him to put valid email in other field.<br />
Otherwise, we want to keep validation turned off. To do this, we use :</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;label for=&quot;cbxSubscribe&quot;&gt; Would you like to subscribe?&lt;/label&gt;
&lt;input id=&quot;cbxSubscribe&quot; type=&quot;checkbox&quot; /&gt;
&lt;input id=&quot;txtSubscriptionEmail&quot; name=&quot;subemail&quot; /&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#sample-form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  rules<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    txtSubscriptionEmail<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
      required<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;#cbxSubscribe:checked&quot;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As simple as that. Element &#8216;txtSubscriptionEmail&#8217; is required depending on evaluation of &#8216;#cbxSubscribe:checked&#8217; expression.</p>
<h3>4. Use CDN from Microsoft AJAX</h3>
<p>Surprise, Surprise! ASP.NET MVC 2 (since preview 2 i guess ) includes jQuery validation plugin to provide client side validation. Definitely good news!</p>
<p>Moreover, Microsoft now provides CDN for plugin:<a href="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js"></a></p>
<ul>
<li><a href="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js">http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js</a></li>
<li><a href="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js">http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js</a></li>
</ul>
<p>As well as documentation for visual studio &#8211; this would allow IntelliSense to work under visual studio (2008 and up):</p>
<ul>
<li><a href="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate-vsdoc.js">http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate-vsdoc.js</a></li>
</ul>
<p>You should make use of CDN wherever possible. It saves you bandwidth, most probably Microsoft serves content faster and there is always a chance your visitors will have it cached already. Note that Google offers CDN for jQuery and some other libraries: <a title="google cdn" href="http://code.google.com/apis/ajaxlibs/" target="_blank">Google AJAX libraries API</a>.</p>
<p>Stay tuned for more updates&#8230;.</p>
<p>I will keep on adding more tips in future.</p>


<p>Related posts:<ol><li><a href='http://itmeze.com/2009/07/firefox-3-0-411-length-required-with-jquery/' rel='bookmark' title='Permanent Link: Firefox 3.0: 411 Length required with JQuery'>Firefox 3.0: 411 Length required with JQuery</a></li>
<li><a href='http://itmeze.com/2009/09/asp-net-mvc-1-0-issue-within-htmlhelper-getmodelstatevalue-method/' rel='bookmark' title='Permanent Link: ASP.NET MVC 1.0 issue within HtmlHelper.GetModelStateValue method'>ASP.NET MVC 1.0 issue within HtmlHelper.GetModelStateValue method</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://itmeze.com/2009/08/tips-for-jquery-validation-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Firefox 3.0: 411 Length required with JQuery</title>
		<link>http://itmeze.com/2009/07/firefox-3-0-411-length-required-with-jquery/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=firefox-3-0-411-length-required-with-jquery</link>
		<comments>http://itmeze.com/2009/07/firefox-3-0-411-length-required-with-jquery/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 11:17:08 +0000</pubDate>
		<dc:creator>ITmeze</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://itmeze.com/?p=53</guid>
		<description><![CDATA[I am currently working on a small project for my own. My favourite (and the only one tester) was complaining on some of &#8220;ajax&#8221; features. Tests were done with use of Firefox 3.0 &#8211; I was developing on Firefox 3.5 and had absolutely no problems with those problematic features. Anyway I decided to check this [...]


Related posts:<ol><li><a href='http://itmeze.com/2009/08/tips-for-jquery-validation-plugin/' rel='bookmark' title='Permanent Link: Tips for jQuery validation plugin'>Tips for jQuery validation plugin</a></li>
<li><a href='http://itmeze.com/2009/06/postjson-how-to-avoid-json-attack/' rel='bookmark' title='Permanent Link: $.postJSON &#8211; how to avoid JSON attack'>$.postJSON &#8211; how to avoid JSON attack</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-7051816622200841";
google_ad_slot = "0915606426";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
<p>I am currently working on a small project for my own. My favourite (and the only one tester) was  complaining on some of &#8220;ajax&#8221; features. Tests were done with use of Firefox 3.0  &#8211; I was developing on Firefox 3.5 and had absolutely no problems with those problematic features. Anyway I decided to check this out an downloaded 3.0 version ( most recent is 3.0.11). You can have multiple instances of Firefox on Your machine &#8211; just make sure You install them in separate directories. Then the best would be to create different user profiles &#8211; like one default and one for testing. You can manage profiles using :</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">firefox.exe -ProfileManager</pre></div></div>

<p>And then You can run prev version by:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">\path\Firefox 3.0\firefox.exe -P test_profile -no-remote</pre></div></div>

<p>Having this set up You can test in Firefox 3.0. I was able to reproduce error and check what is going on in firebug.<br />
I was receiving HTTP 411 error, which says:</p>
<blockquote><p>Your Web server thinks that the HTTP data stream sent by the client (e.g. your Web browser or our CheckUpDown robot) should include a &#8216;Content-Length&#8217; specification. This is typically used only for HTTP methods that result in the placement of data on the Web server, not the retrieval of data from it.</p></blockquote>
<p>It looks like jQuery (1.3.2) ajax calls with data parameter set to &#8216;null&#8217; was causing this to happen.</p>
<p>Simple solution for me was to set &#8216;{}&#8217; as data parameter value instead of &#8216;null&#8217;. Moreover, You can change method that I already mentioned about, <a title="jsonPOST with jQuery" href="http://itmeze.com/2009/06/postjson-how-to-avoid-json-attack/" target="_blank">postJSON</a> with this fix:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">postJSON</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
         data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
     $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> callback<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>BTW I already use Firefox 3.5 during development &#8211; it consumes less resources than previous versions () so I strongly recommend upgrading to newest version.</p>


<p>Related posts:<ol><li><a href='http://itmeze.com/2009/08/tips-for-jquery-validation-plugin/' rel='bookmark' title='Permanent Link: Tips for jQuery validation plugin'>Tips for jQuery validation plugin</a></li>
<li><a href='http://itmeze.com/2009/06/postjson-how-to-avoid-json-attack/' rel='bookmark' title='Permanent Link: $.postJSON &#8211; how to avoid JSON attack'>$.postJSON &#8211; how to avoid JSON attack</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://itmeze.com/2009/07/firefox-3-0-411-length-required-with-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
