views:

736

answers:

1

Can I dynamically set errorContainer in jQuery validation, which means showing different error container base on the button clicked.

This is what I am trying to do, but seems doesn't work:

     $('#b1').click(function(evt) {
        $('#form1').validate().resetForm();
        validator.settings.errorContainer = $('#m1');
        validator.settings.errorLabelContainer = $('ul', $('#m1'));

        ValidateAndSubmit(evt)
        if (evt.isDefaultPrevented())
            return false;

        alert("b1 clicked");
    });

    $('#b2').click(function(evt) {
        $('#form1').validate().resetForm();
        validator.settings.errorContainer = $('#m2');
        validator.settings.errorLabelContainer = $('ul', $('#m2'));         

        ValidateAndSubmit(evt);
        if (evt.isDefaultPrevented())
            return false;

        alert("b2 clicked");
    });

the reason I'm doing this, because I'm using asp.net webform all my module inside one form tag, so I can't define another form inside existing form and set validation for each form, and I can only have one validation bind to the form.

I am using encosia's solution to simulate validation group using jQuery validation for sub-form under one form tag which is working perfectly, but in some case sub-forms under different tabs, so I want to showing the error container in each tab.

I have created a simple sample to explain what i'm trying to do sample here

A: 

If you already download the zip file, you will find a live site example in it. My favorite is the RTM example. The page have two type of form field, the one inside the table, and outside the table. For the field inside the table, the error message will appear in the table's column beside the column of field with error. For the field outside table, the error message will appear right beside the form field.

The form validation library is clearly lack of proper documentation. I learn all cool trick from the sample live site.

Donny Kurnia
Hi Donny Kurnia, i couldn't really found the RTM example, i actually want grouping all error msgs in one msg container rather than errors next to each input field, now the problem is i can't set the msg container dynamically.
The RTM example is here: http://jquery.bassistance.de/validate/demo/milk/For placing the error message in your own container, see the example here: http://jquery.bassistance.de/validate/demo/errorcontainer-demo.html
Donny Kurnia
You can find the link for demos and examples at the end of this page: http://jquery.bassistance.de/validate/demo/
Donny Kurnia