Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a form that has multiple inputs array, but I just want some that are mandatory, which you want to apply the class ignoring ignore. the problem is that jquery validate check all mandatory. How could I avoid this:

a simple example:

html

<form id='register' name='register' method='post' action='' >   
enter code herearray1: <input type='text' name='name[]' id='name'/>
   input type 1: <input type='text' name='name[]' id='name'/>
   input type 1: <input type='text' class="noValidate" name='name[]' id='name'/>
   input type 1: <input type='text' name='name[]' id='name'/>

   <input type='submit' name='Submit' value='Submit' />

</form>

function that validate the form

function ValidateFormNewContract()
{
    $('#formAltaContrac').submit(function(event)
    {
        event.preventDefault();
        $('#formAltaContrac').validate().settings.ignore = []; 
    });

    $('#formAltaContrac').validate(
    {
        ignore: ".noValidate",
        invalidHandler: function(e,validator) 
        {
            if(validator.errorList.length > 0)
            {
                var id = $(validator.errorList[0].element).parent().parent().parent().parent().parent()[0].id;
                $('a[href=#'+id+']').click();
                $(validator.errorList[0].element).focus();
            }
        },
        submitHandler: function(form) {
//            alert('enviado');
            SendNewContractData();
        },
        rules: {
            'name[]':{required: true},
//            
        }
    });
}

note: I have modified jquery validate to perform validations array inputs,

validations array inputs makes them well, but do not get to ignore the class

and another question, how could I do to make the span Feeding Fail jquery to validate an input spread to other inputs to array fault?

share|improve this question
    
You can't use the same name more than once. jQuery Validate plugin uses the name to keep track of inputs so it must be unique. –  Sparky May 29 '14 at 19:33

1 Answer 1

up vote 0 down vote accepted

Your code...

enter code herearray1: <input type='text' name='name[]' id='name'/>
input type 1: <input type='text' name='name[]' id='name'/>
input type 1: <input type='text' class="noValidate" name='name[]' id='name'/>
input type 1: <input type='text' name='name[]' id='name'/>

1) The biggest problem is that all of your input elements contain the same name="name[]". Poor semantics aside, you cannot duplicate the name attribute since the plugin uses it to keep track of the input elements.

2) As far as "ignoring" inputs, if you don't specify a rule for an input, then the input will not be evaluated. Simple enough, and once you fix the naming issues above, this part will take care of itself.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.