3

I'm using jquery Ui tabs and validation plugins, for my forms, the forms divided in 4 steps(like wizard) and navigate trough the tabs by navigation(not tabs), each steps contain form element and need to be validate,; her is my code:

<script>
            $('#registration').validate({
                errorClass: "warning",
                debug:true,
                onkeyup: true,
                onblur: true,
            });

        var $tabs = $('#tabs').tabs();
        $('.next').click(function() {                            
               $tabs.tabs('select', $(this).attr("rel"));
           });

        $('.back').click(function() {
            $tabs.tabs('select', $(this).attr("rel"));
         });
</script>

    <div id="tabs">
<ul style="display:none">
    <li><a href="#tabs-1">1</a></li>
    <li><a href="#tabs-2">2</a></li>
    <li><a href="#tabs-3">3</a></li>
    <li><a href="#tabs-4">4</a></li>
</ul>
<form id="registration" name="registration" method="post" action="<?php $PHP_SELF ?>">
<div id="tabs-1">
    <input name="test1" type="text" class="required" /><br />
    <input name="test2" type="text" class="required" /><br />
    <input name="test3" type="text" class="required" /><br />
    <input name="test4" type="text" class="required" /><br />

    <button type="button" class="next" rel="2" name="test">Next</button>

</div>
<div id="tabs-2">
    <input name="test1" type="text" class="required" /><br />
    <input name="test2" type="text" class="required" /><br />
    <input name="test3" type="text" class="required" /><br />
    <input name="test4" type="text" class="required" /><br />

    <button type="button" class="back" rel="1" name="test">Back</button>
    <button type="button" class="next" rel="3" name="test">Next</button>
</div>
  <div id="tabs-3">
    <input name="test1" type="text" class="required" /><br />
    <input name="test2" type="text" class="required" /><br />
    <input name="test3" type="text" class="required" /><br />
    <input name="test4" type="text" class="required" /><br />

    <button type="button" class="back" rel="2" name="test">Back</button>
    <button type="button" class="next" rel="4" name="test">Next</button>

</div>
<div id="tabs-4">
    <input name="test1" type="text" class="required" /><br />
    <input name="test2" type="text" class="required" /><br />
    <input name="test3" type="text" class="required" /><br />
    <input name="test4" type="text" class="required" /><br />

    <button type="button" class="back" rel="3" name="test">Back</button>
    <button type="submit" class="submit"  name="test">Register</button>

</div>
</form>
</div>

i try to validate in each step but i cant, please help me out

2 Answers 2

1

You can add the ignore option to ignore the tabs that aren't currently visible via the :hidden selector, like this:

$('#registration').validate({
  errorClass: "warning",
  debug:true,
  onkeyup: true,
  onblur: true,
  ignore: ':hidden'
});
Sign up to request clarification or add additional context in comments.

5 Comments

i would like to validate when i clicks next button, but it is not working what i try; your code also is not working :(
@Pezhman - Add a validation call, for example: $('.next').click(function() { $tabs.tabs('select', $(this).attr("rel")); $('#registration').valid(); }); is that what you're after?
:( it is not working ! i have tried that one! when i click next it validate and it goes to the next tab, but what i want is, it must validate and not go to the next step, until writing all the required filed,
@Pezhman - Oh, right of course, like this: $('.next').click(function() { if($('#registration').valid()) $tabs.tabs('select', $(this).attr("rel")); });
wow tnx, it is working , but there is an small problem, if in the first steps shows errors, in all steps(tabs) the error message are visible!
1

I found the solution, link text

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.