<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Customizing jQuery Validation</title>
	<atom:link href="http://blogs.teamb.com/craigstuntz/2009/01/15/37923/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.teamb.com/craigstuntz/2009/01/15/37923/</link>
	<description>C# • Entity Framework • Functional Programming • MVC • Web</description>
	<pubDate>Sun, 12 Feb 2012 04:45:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: CB</title>
		<link>http://blogs.teamb.com/craigstuntz/2009/01/15/37923/#comment-38633</link>
		<dc:creator>CB</dc:creator>
		<pubDate>Fri, 23 Dec 2011 05:16:47 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=37923#comment-38633</guid>
		<description>Not sure if jsherk meant to replace one line with the other, but for anyone looking to do custom inline errors messages, I believe the link jsherk is talking about is supposed to go in the extra conditional code that is in the article example. Here's my new "required":

$.validator.addMethod("required", function(value, element, param) {
// reg-first-name custom errors
if (element.id=='reg-first-name' ) {
if( value == '' ){
$.validator.messages.required = "Please enter your first name.";
return false;
} else if( !value.match(/^[A-Za-z]+$/) ){
$.validator.messages.required = "Please enter only alpha characters ( Aa-Zz )";
return false;
}
return true;
}
return $.validator.methods.oldRequired.call(this, value, element, param);
},
$.validator.messages.required // use default message
);</description>
		<content:encoded><![CDATA[<p>Not sure if jsherk meant to replace one line with the other, but for anyone looking to do custom inline errors messages, I believe the link jsherk is talking about is supposed to go in the extra conditional code that is in the article example. Here&#8217;s my new "required":</p>
<p>$.validator.addMethod("required", function(value, element, param) {<br />
// reg-first-name custom errors<br />
if (element.id==&#8217;reg-first-name&#8217; ) {<br />
if( value == &#8221; ){<br />
$.validator.messages.required = "Please enter your first name.";<br />
return false;<br />
} else if( !value.match(/^[A-Za-z]+$/) ){<br />
$.validator.messages.required = "Please enter only alpha characters ( Aa-Zz )";<br />
return false;<br />
}<br />
return true;<br />
}<br />
return $.validator.methods.oldRequired.call(this, value, element, param);<br />
},<br />
$.validator.messages.required // use default message<br />
);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jQuery form validator custom validation method using addmethod for validating date of birth (dob) - ideas for design, code and seo - ideas for design, code and seo</title>
		<link>http://blogs.teamb.com/craigstuntz/2009/01/15/37923/#comment-26497</link>
		<dc:creator>jQuery form validator custom validation method using addmethod for validating date of birth (dob) - ideas for design, code and seo - ideas for design, code and seo</dc:creator>
		<pubDate>Thu, 07 Apr 2011 21:54:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=37923#comment-26497</guid>
		<description>[...] This post at stack overflow gave me the initial starting point, Custom date format with jQuery validation plugin and this post on jQuery forums helped with the custom error messages, Validation Plugin, changing message with addMethod and Craig Stuntz’s Customizing jQuery Validation [...]</description>
		<content:encoded><![CDATA[<p>[...] This post at stack overflow gave me the initial starting point, Custom date format with jQuery validation plugin and this post on jQuery forums helped with the custom error messages, Validation Plugin, changing message with addMethod and Craig Stuntz’s Customizing jQuery Validation [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jsherk</title>
		<link>http://blogs.teamb.com/craigstuntz/2009/01/15/37923/#comment-22213</link>
		<dc:creator>jsherk</dc:creator>
		<pubDate>Tue, 11 Jan 2011 04:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=37923#comment-22213</guid>
		<description>Thanks for this... I was struggling with trying to figure out how to create dynamic custom messages with the addmethod and the key line was:
jQuery.validator.messages.required // use default message

So I used:
$.validator.messages.nameOfMethod = 'custom message here';
and it worked!

Thanks again</description>
		<content:encoded><![CDATA[<p>Thanks for this&#8230; I was struggling with trying to figure out how to create dynamic custom messages with the addmethod and the key line was:<br />
jQuery.validator.messages.required // use default message</p>
<p>So I used:<br />
$.validator.messages.nameOfMethod = &#8216;custom message here&#8217;;<br />
and it worked!</p>
<p>Thanks again</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manoj</title>
		<link>http://blogs.teamb.com/craigstuntz/2009/01/15/37923/#comment-19802</link>
		<dc:creator>Manoj</dc:creator>
		<pubDate>Wed, 03 Nov 2010 19:33:36 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=37923#comment-19802</guid>
		<description>Just what I was looking for.  

I wanted an optional date validation and was using the dateITA from the additionalmethods.js.  However, I had a watermark in the text box due to which the date validation would always trigger.  

Extended the dateITA to my own custom function which checked if it there was a watermark or not and then if necessary called the original dateITA method.  Worked like  charm!</description>
		<content:encoded><![CDATA[<p>Just what I was looking for.  </p>
<p>I wanted an optional date validation and was using the dateITA from the additionalmethods.js.  However, I had a watermark in the text box due to which the date validation would always trigger.  </p>
<p>Extended the dateITA to my own custom function which checked if it there was a watermark or not and then if necessary called the original dateITA method.  Worked like  charm!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Garfield Lindo</title>
		<link>http://blogs.teamb.com/craigstuntz/2009/01/15/37923/#comment-15271</link>
		<dc:creator>Garfield Lindo</dc:creator>
		<pubDate>Mon, 22 Mar 2010 13:16:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=37923#comment-15271</guid>
		<description>Hi Craig,
I'm hoping you might have some insight into an issue I'm facing with the validator.addMethod.  I'll describe below:

Specifically my question deals with the message part of the addMethod function.  I have the following code in my document.ready function.

 $(document).ready(function() {
var message = "";
            jQuery.validator.addMethod("IsSelectionValid", function(value, element, param) {
                var result = true;


                if ($('#auditTypeDropDownList option:selected').val() == '1' &#38;&#38; element.id == 'opinionDropDownList') {
                    if (value == '7' &#124;&#124; value == '8') {//7 = other 8 = N/A
                        result = false;
                        message = "* Can use all choices except Other and N/A";
                    }
                    else {
                        result = true;
                    }
                }
                else if ($('#auditTypeDropDownList option:selected').val() == '2' &#38;&#38; element.id == 'opinionDropDownList' &#124;&#124;
                $('#auditTypeDropDownList option:selected').val() == '3' &#38;&#38; element.id == 'opinionDropDownList') {
                    if (value == '8') {
                        result = true;
                    }
                    else {
                        result = false;
                        message = "* N/A is the only available option for audit opinion with this audit type";
                    }
                }
                return result;
            },message);
});

The problem is I'm unable to get the message to be displayed.  When I put the message variable in an alert I can see the text just fine. However when I put the variable in its expected place I get nothing.  However if I put a string like "* Can use all choices except Other and N/A" it displays.  I just don't seem to be able to use a variable.  Any thoughts?

&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Response: &lt;/strong&gt;Well, you just added a validator with an empty message. Your validation function does not run until well after the validator has already been added, so the message variable will be unassigned when you add the validator. It seems to me like you are attempting to roll two different validation rules into a single validation. Why not just make them two separate rules?&lt;/em&gt;&lt;/blockquote&gt;

</description>
		<content:encoded><![CDATA[<p>Hi Craig,<br />
I&#8217;m hoping you might have some insight into an issue I&#8217;m facing with the validator.addMethod.  I&#8217;ll describe below:</p>
<p>Specifically my question deals with the message part of the addMethod function.  I have the following code in my document.ready function.</p>
<p> $(document).ready(function() {<br />
var message = "";<br />
            jQuery.validator.addMethod("IsSelectionValid", function(value, element, param) {<br />
                var result = true;</p>
<p>                if ($(&#8217;#auditTypeDropDownList option:selected&#8217;).val() == &#8216;1&#8242; &amp;&amp; element.id == &#8216;opinionDropDownList&#8217;) {<br />
                    if (value == &#8216;7&#8242; || value == &#8216;8&#8242;) {//7 = other 8 = N/A<br />
                        result = false;<br />
                        message = "* Can use all choices except Other and N/A";<br />
                    }<br />
                    else {<br />
                        result = true;<br />
                    }<br />
                }<br />
                else if ($(&#8217;#auditTypeDropDownList option:selected&#8217;).val() == &#8216;2&#8242; &amp;&amp; element.id == &#8216;opinionDropDownList&#8217; ||<br />
                $(&#8217;#auditTypeDropDownList option:selected&#8217;).val() == &#8216;3&#8242; &amp;&amp; element.id == &#8216;opinionDropDownList&#8217;) {<br />
                    if (value == &#8216;8&#8242;) {<br />
                        result = true;<br />
                    }<br />
                    else {<br />
                        result = false;<br />
                        message = "* N/A is the only available option for audit opinion with this audit type";<br />
                    }<br />
                }<br />
                return result;<br />
            },message);<br />
});</p>
<p>The problem is I&#8217;m unable to get the message to be displayed.  When I put the message variable in an alert I can see the text just fine. However when I put the variable in its expected place I get nothing.  However if I put a string like "* Can use all choices except Other and N/A" it displays.  I just don&#8217;t seem to be able to use a variable.  Any thoughts?</p>
<blockquote><p><em><strong>Response: </strong>Well, you just added a validator with an empty message. Your validation function does not run until well after the validator has already been added, so the message variable will be unassigned when you add the validator. It seems to me like you are attempting to roll two different validation rules into a single validation. Why not just make them two separate rules?</em></p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Teguh Eko Budiarto</title>
		<link>http://blogs.teamb.com/craigstuntz/2009/01/15/37923/#comment-13611</link>
		<dc:creator>Teguh Eko Budiarto</dc:creator>
		<pubDate>Wed, 27 Jan 2010 10:56:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=37923#comment-13611</guid>
		<description>I was trying to create multi step form using tab approach, and need to validate each step without actually submitting the form.
This is exactly the remedy of my problem. Extending the required method to work only for the page that the user is in. THANK YOU!!!</description>
		<content:encoded><![CDATA[<p>I was trying to create multi step form using tab approach, and need to validate each step without actually submitting the form.<br />
This is exactly the remedy of my problem. Extending the required method to work only for the page that the user is in. THANK YOU!!!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

