[jQuery] Re: (Validation) How to use with Multi-Select?

2009-08-27 Thread Jörn Zaefferer

Here are examples with multi-selects:
http://jquery.bassistance.de/validate/demo/radio-checkbox-select-demo.html

Jörn

On Thu, Aug 27, 2009 at 3:04 PM, Psyclom...@datamodel.org wrote:

 I have a form with a multi-select field that needs to be validated, so
 at least one option is selected.  Is there a setting I'm missing in
 the validation plug-in?

 Thanks in advance.



[jQuery] Re: (Validation) How to use with Multi-Select?

2009-08-27 Thread Psyclo

Thanks for responding so quickly.
Unfortunately, my form just isn't working like yours.  I don't see
what I've done wrong.  Maybe you can see something?

Here is the code:

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://
www.w3.org/TR/html4/loose.dtd
html
head
script type=text/javascript src=/jquery/jquery-1.3.2.min.js/
script
script type=text/javascript src=/jquery/jquery.validate.js/
script
form name=brief id=briefform enctype=multipart/form-data
action=/amstest/edit.php method=POST
select name=ROLE_1 id=ROLE_1 validate=required:true, minlength:1
multiple=multiple title=Please specify at least one person
size=5
option value=''Select a person
option value=1First Person
option value=2Second Person
option value=3Third Person
/select
input type=submit value=Validate Selecttests/
/form

script language=JavaScript type=text/javascript
$.validator.addClassRules({
multirequired: {
required: true,
minlength: 1
}
});

$.validator.addMethod(allOrNothing, function(value, element) {
var i, sply, prod, prog, amt, allthere;
allthere = new Array();
for (i=0; document.getElementById('SPLY_'+i)!=null; i++)
{
allthere[i] = -1;
sply = document.getElementById('SPLY_'+i).value;
prod = document.getElementById('prod_'+i).value;
prog = document.getElementById('prog_'+i).value;
amt  = document.getElementById('amt_'+i).value;
if (sply0 || prod0 || prog0 || amt.length0)
allthere[i] = (sply0  prod0  prog0  
amt.length0);
}
return (element.id=='amt0'?element.length0:element.value0) ||
allthere[0];
}, brData Missing);

$.validator.addClassRules({
allOrNothing: { allOrNothing: true }
});

form = $(#briefform)
form.validate({
debug: true,
success: valid,
submitHandler: function() { alert(Submitted!) },
errorPlacement: function(error, element) {
tid = element.attr(id);
for (i=0; document.getElementById('SPLY_'+i)!=null; i++)
if (tid == SPLY_+i || tid == prod_+i || tid 
== prog_+i ||
tid == amt_+i)
error.insertAfter(#DESC_+i);
else
error.insertAfter(element);
},
errorClass: errormsg
});
/script
/body
/html

On Aug 27, 8:09 am, Jörn Zaefferer joern.zaeffe...@googlemail.com
wrote:
 Here are examples with 
 multi-selects:http://jquery.bassistance.de/validate/demo/radio-checkbox-select-demo...

 Jörn



 On Thu, Aug 27, 2009 at 3:04 PM, Psyclom...@datamodel.org wrote:

  I have a form with a multi-select field that needs to be validated, so
  at least one option is selected.  Is there a setting I'm missing in
  the validation plug-in?

  Thanks in advance.- Hide quoted text -

 - Show quoted text -