0

Ні, all!

I have a little question about jQuery.Validation plugin: - Can I complete validation for input fields that are not form fields (i.e no in the "form" tag) using jQuery.Validation plugin?

Thanks.

1 Answer 1

1

Yes you can, but the field still needs to be inside a set of <form> tags. However, you do not need to "submit" this form in order to check validation on the field(s) inside. You use the .valid() method to check this form independently of form submission.

http://jsfiddle.net/9fgVN/13/

<form id="myNonsubmitForm" action="#">
    <textarea name="comments" id="comments" rows="5" cols="30"></textarea>
</form>

<button id="myButton">Click to Check Validation Status</button>
<input type="text" id="output" />

 

$(document).ready(function() {

    $("#myNonsubmitForm").validate({
        validClass: 'valid',  // as per your configuration
        rules: {  // set rules as per your configuration
            comments: {
                required: false,
                maxlength: 10
            }
        },
        errorPlacement: function(error, element) {
             // use this to control placement of error messages
             // removal of errorPlacement handler will result in message appearing next to field automatically.
        }
    });

    $("#myButton").click(function() { // validate on button click for this example
        if($("#myNonsubmitForm").valid()){
            $('#output').val('passed');
        } else {
            $('#output').val('failed');
        };
    });

});
Sign up to request clarification or add additional context in comments.

2 Comments

@ramb0tn1k, So why can't you use form tags?
You're right. I reviewed the documentation in detail and came to the conclusion that the reason why i can't use the form there is no. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.