views:

344

answers:

2

hey folks,

I'm using the fantastic jquery .validate plugin from Jörn Zaefferer at bassistance

I'm using asp.net, so have one long form, though the form is broken up into 3 sections via a jquery accordion with buttons to switch between accordion panes.

I want the button in pane one to validate pane one fields, same with pane two, etc.

Obviously in any other technology, I'd go with multiple forms and have no difficulty at all, though I can't do this in .net.

I think what I need is almost a $('#aspnetForm').validate().unbind() or something similar - on accordion click I'm asking to re-validate the form, so I know which page I'm on and I could then just setup new rules etc.

I tried clearing out the rules $('#aspnetForm').validate().rules('remove') though it seems I would have to do this for each field rather than the form itself?

I can post any code examples necessary, though the overall script is sizable now so I'd have to dig chunks out.

Hopefully I'm making logical sense above - basically, a means of clearing out all rules so that I can create new ones because I'm in a different accordion panel is the solution I'm hoping for, though I'm struggling.

Many thanks, Terry

+1  A: 

I would try having a flag set when any portion of the form is displayed like

<div id="form_section_1" class="displayed">
     ....
</div>
<div id="form_section_2">
     ....
</div>
<div id="form_section_3">
     ....
</div>

Then in your validation rules, make them conditional.

if($('#form_section_1').attr('class').search('displayed') != -1){
     var is_section_1_displayed = true;
}
else{ var is_section_1_displayed = false;

Do that for each one (maybe a more efficient way)

Then in your validation rules do something like

email: {
         required = is_section_1_displayed;
       }

Assuming email is in the first section of the form.

idrumgood
A: 

this is indeed what I was doing, and after some prolonged firebug work it seems one of the selectors wasn't being cleared, so the wrong rules were being loaded up.

Now they're resolved, each call to .validate has its own set of rules, and unlick (say) the .click event, they don't appear to be additive so page1.validate with 3 rules clears out all page2.validate rules.

Thanks for your input though idrumgood, marked your answer up to say thanks for any input.

Cheers, Terry

Terry_Brown