1

I have some forms that I am validating with jQuery Validate plugin. The next code by examples, works fine:

<script type="text/javascript">
$(document).ready(function(){
    $("#transactionform").validate({
       rules: {
        'cliente[nombre]': {
           required: true,
           minlength: 5
        },
        'cliente[id]': {
           required: true
        }
      }
    });
});
</script>

In this form 'cliente[nombre]' is a simple text input, and 'cliente[id]' is a hidden field that must be filled by some javascript function. Actually, the validation errors are displayed next to the corresponding field, and that includes the hidden fields.

What I want is to have a special div for displaying the validating errors of hidden inputs and displaying non-hidden input errors using the corresponding label (as it is now).

1 Answer 1

4

I think you could make use of the errorPlacement function and utilize it with some custom element selection e.g.

errorPlacement: function(error, element) {
    error.appendTo('#invalid-' + element.attr('id'));
}

You could then position each error message individually using custom html, example: http://jsfiddle.net/FZUnu/

I hope this helps!

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

Comments

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.