[jQuery] Re: validation - multiple errorPlacements

2009-08-12 Thread nouky


I did not understand this

Jörn Zaefferer wrote:
 
 
 seedy schrieb:
 Is it possible to use errorPlacement with the validation plugin to have a
 different placement for each field validated?

 ie.
 $('#testForm').validate({
  rules:{
  firstname:{required:true},
  integer:{required:true}
  }
 })

 I would like to have the error for firstname appended to $('#div1') , and
 errors for integer before $('#div2')
   
 You can use the errorPlacement option for that. Its far from perfect, 
 but allows you to do every placement you can think of.
 
 One example of the usage of errorPlacement can be found here: 
 http://dev.jquery.com/view/trunk/plugins/validate/demo-test/milk/
 The interesting part:
 
 |// the errorPlacement has to take the table layout into account 
 errorPlacement: function(error, element) { 
 if ( element.is(:radio) ) 
 error.appendTo( element.parent().next().next() ); 
 else if ( element.is(:checkbox) ) 
 error.appendTo ( element.next() ); 
 else 
 error.appendTo( element.parent().next() ); 
 }, 
 |
 
 -- Jörn
 
 

-- 
View this message in context: 
http://www.nabble.com/validation---multiple-errorPlacements-tp12781506s27240p24938662.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



[jQuery] Re: validation - multiple errorPlacements

2007-09-19 Thread Jörn Zaefferer


seedy schrieb:

Is it possible to use errorPlacement with the validation plugin to have a
different placement for each field validated?

ie.
$('#testForm').validate({
rules:{
firstname:{required:true},
integer:{required:true}
}
})

I would like to have the error for firstname appended to $('#div1') , and
errors for integer before $('#div2')
  
You can use the errorPlacement option for that. Its far from perfect, 
but allows you to do every placement you can think of.


One example of the usage of errorPlacement can be found here: 
http://dev.jquery.com/view/trunk/plugins/validate/demo-test/milk/

The interesting part:

|// the errorPlacement has to take the table layout into account 
   errorPlacement: function(error, element) { 
   if ( element.is(:radio) ) 
   error.appendTo( element.parent().next().next() ); 
   else if ( element.is(:checkbox) ) 
   error.appendTo ( element.next() ); 
   else 
   error.appendTo( element.parent().next() ); 
   }, 
|


-- Jörn


[jQuery] Re: validation - multiple errorPlacements

2007-09-19 Thread seedy


wow I hadn't considered using an if to check the id of the element.  Feeling
really dumb right now.  Thanks!


Jörn Zaefferer wrote:
 
 
 seedy schrieb:
 Is it possible to use errorPlacement with the validation plugin to have a
 different placement for each field validated?

 ie.
 $('#testForm').validate({
  rules:{
  firstname:{required:true},
  integer:{required:true}
  }
 })

 I would like to have the error for firstname appended to $('#div1') , and
 errors for integer before $('#div2')
   
 You can use the errorPlacement option for that. Its far from perfect, 
 but allows you to do every placement you can think of.
 
 One example of the usage of errorPlacement can be found here: 
 http://dev.jquery.com/view/trunk/plugins/validate/demo-test/milk/
 The interesting part:
 
 |// the errorPlacement has to take the table layout into account 
 errorPlacement: function(error, element) { 
 if ( element.is(:radio) ) 
 error.appendTo( element.parent().next().next() ); 
 else if ( element.is(:checkbox) ) 
 error.appendTo ( element.next() ); 
 else 
 error.appendTo( element.parent().next() ); 
 }, 
 |
 
 -- Jörn
 
 

-- 
View this message in context: 
http://www.nabble.com/validation---multiple-errorPlacements-tf4482247s15494.html#a12783968
Sent from the JQuery mailing list archive at Nabble.com.



[jQuery] Re: validation - multiple errorPlacements

2007-09-19 Thread seedy


ok now a follow up question

I have 3 text boxes that make up a telephone number.  I want validation to
fail if any of the text boxes are not complete, but I only want to show one
message for the failure, not one per textbox.  Any recommended ways of doing
this?



Jörn Zaefferer wrote:
 
 
 seedy schrieb:
 Is it possible to use errorPlacement with the validation plugin to have a
 different placement for each field validated?

 ie.
 $('#testForm').validate({
  rules:{
  firstname:{required:true},
  integer:{required:true}
  }
 })

 I would like to have the error for firstname appended to $('#div1') , and
 errors for integer before $('#div2')
   
 You can use the errorPlacement option for that. Its far from perfect, 
 but allows you to do every placement you can think of.
 
 One example of the usage of errorPlacement can be found here: 
 http://dev.jquery.com/view/trunk/plugins/validate/demo-test/milk/
 The interesting part:
 
 |// the errorPlacement has to take the table layout into account 
 errorPlacement: function(error, element) { 
 if ( element.is(:radio) ) 
 error.appendTo( element.parent().next().next() ); 
 else if ( element.is(:checkbox) ) 
 error.appendTo ( element.next() ); 
 else 
 error.appendTo( element.parent().next() ); 
 }, 
 |
 
 -- Jörn
 
 

-- 
View this message in context: 
http://www.nabble.com/validation---multiple-errorPlacements-tf4482247s15494.html#a12784330
Sent from the JQuery mailing list archive at Nabble.com.



[jQuery] Re: validation - multiple errorPlacements

2007-09-19 Thread Jörn Zaefferer


seedy schrieb:

ok now a follow up question

I have 3 text boxes that make up a telephone number.  I want validation to
fail if any of the text boxes are not complete, but I only want to show one
message for the failure, not one per textbox.  Any recommended ways of doing
this?
  
The first thing that I'd come up with is to put a single custom method 
on the first/last field (depending on your error placement on or the 
other may be easier) and check the other two fields inside that method.


-- Jörn