Ticket #2561 (closed enhancement: invalid)
[validate] custom errorPlacement
| Reported by: | sniffer | Owned by: | joern |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | plugin | Version: | |
| Keywords: | validation errorPlacement | Cc: | |
| Blocking: | Blocked by: |
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
Change History
comment:1 Changed 5 years ago by joern
- Owner set to joern
- Summary changed from validation plugin: custom errorPlacement to [validate] custom errorPlacement
comment:2 Changed 5 years ago by joern
- Status changed from new to closed
- Resolution set to invalid
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
