[jQuery] [validate] validation plugin custom errorPlacement for datepicker

[jQuery] [validate] validation plugin custom errorPlacement for datepicker


Hi
I've been using the validation plugin quite happily (it's a great
plugin), but I've just tried to implement a datepicker on one of my
forms and I cannot get the error to show correctly.
My original markup is like this:
<label for="title_publication_date">Publication date:</label>
<input id="title_publication_date" name="title_publication_date"
type="text" />
<span class="status"></span>
But the datepicker (which is part of jquery UI) amends the markup on
the fly to produce:
<label for="title_publication_date">Publication date:</label>
<span class="datepicker_wrap">
<input id="title_publication_date" class="hasDatepicker"
type="text" name="title_publication_date"/>
<img class="datepicker_trigger" title="..." alt="..." src="../../
Common/Images/calendar.gif"/>
</span>
<span class="status"></span>
I've got the following validation rules on this input:
title_publication_date: { required: true, date: true }
Unfortunately, if I leave the input field blank the validation doesn't
appear to run - or I probably should say - the validation runs, but I
can't see the error message.
I've tried amending the errorPlacement as follows (see 2nd else if
statement), but this doesn't seem to work:
errorPlacement: function(error, element) {
if ( element.is(":radio") )
error.appendTo( element.parent().next().next('span') );
else if ( element.is(":checkbox") )
error.appendTo ( element.next('span') );
else if ( element.is(":input" &&
element.is("#title_publication_date")))
error.appendTo ( element.parent().next('span') );
else
error.appendTo( element.next('span') );
}
Is there any way that I can target the "#title_publication_date" input
specifically and have a cusotm errorPlacement for it?
Thanks for your time
Sniffer