Skip to main content

Bug Tracker

Side navigation

#2561 closed enhancement (invalid)

Opened March 19, 2008 08:16PM UTC

Closed July 13, 2008 12:34PM UTC

Last modified March 15, 2012 06:31PM UTC

[validate] custom errorPlacement

Reported by: sniffer Owned by: joern
Priority: minor Milestone:
Component: plugin Version:
Keywords: validation errorPlacement Cc:
Blocked by: Blocking:
Description

Text below taken from http://groups.google.com/group/jquery-en/browse_thread/thread/55497acab96f23ac#

I have created a test page at Jörn's request - this can be found here: http://snifferweb.com/Misc/jquery/calendartest.php

Let me know if you need any more info.

Thanks for your time

Sniffer



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

Attachments (0)
Change History (2)

Changed May 25, 2008 11:37AM UTC by joern comment:1

owner: → joern
summary: validation plugin: custom errorPlacement[validate] custom errorPlacement

Changed July 13, 2008 12:34PM UTC by joern comment:2

resolution: → invalid
status: newclosed

This works fine on your testpage:

if ( element.is("#textdate1") )
	error.appendTo ( element.parent().next('span') );
else
	error.appendTo( element.next('span') );
},

I therefore consider this ticket invalid.