Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Validation plugin - Validating hidden inputs and not visible? [duplicate]

How would I validate hidden inputs and not visible text inputs with jQuery Form Validation plugin? The problem is, that I'm using auto-suggest plugin, which generates a hidden input for selected items:

<input id="hiddenInput" type="hidden" name="something" value="1" />

I have 2 inputs like this (both of them only allow 1 item), which I want to validate and display the error in parent <td>. This is what I've gotten so far, but it doesn't display the error or submit a form, if the value is actually a number.

$("#form1").validate({
        rules: {
            something: {
                number:true,
                min:1,
                required:true
            }
        }
        })
like image 781
Gregor Menih Avatar asked Oct 31 '11 10:10

Gregor Menih


2 Answers

To allow validation of hidden elements, override the ignore and set it to empty string:

$("#form1").validate({
    ignore: "",
    rules: {
        something: {
            number:true,
            min:1,
            required:true
        }
    }
});
like image 138
Josh Avatar answered Nov 15 '22 07:11

Josh


You can use ignore option like this:

$("#form1").validate({
    ignore: "input[type='text']:hidden",
    rules: {
        something: {
            number:true,
            min:1,
            required:true
        }
    }
});

Default value of ignore option is :hidden which ignores all hidden fields and non-visible fields (display: none etc.)

like image 30
Emre Erkan Avatar answered Nov 15 '22 08:11

Emre Erkan