thecodemine / formwizard

jQuery plugin based on top of jQuery UI which turns a form into a multistep wizard. Integrates with the jQuery form plugin for AJAX submission of the form, the validation plugin for client side validation and the BBQ plugin for enabling the browsers back and forward buttons.
140 stars 54 forks source link

Disable buttons on step or disallow continue on form input. #18

Closed jonferguson closed 11 years ago

jonferguson commented 12 years ago

Hello, thanks for the great work.

I have a dropdown with two options, Yes or No.

if yes is selected, continue to step 2. if no is selected, continue to a sorry step and don't allow further submission of form.

Can this be done?

Also, does this work with codeigniter?

Many thanks.

thecodemine commented 12 years ago

Hi,

Would you like the user to be able to go back from the "sorry" step and be able to select "yes" instead?

One solution would be to add bind a callback function to the step_shown event that is triggered each time a new step is shown. This function would check whether the current step is the "sorry" step (has the id 'sorry' in the example below) and in that case hide the submit button (has the id 'next' in the example).

    <script type="text/javascript">
            $(function(){
                $("#demoForm").formwizard({ 
                    formPluginEnabled: true,
                    validationEnabled: true,
                    focusFirstInput : true,
                    formOptions :{
                        success: function(data){$("#status").fadeTo(500,1,function(){ $(this).html("You are now registered!").fadeTo(5000, 0); })},
                        beforeSubmit: function(data){$("#data").html("data sent to the server: " + $.param(data));},
                        dataType: 'json',
                        resetForm: true
                    }   
                 }
                ).bind("step_shown",function(event,data){
                    var nextButton = $("#next").show();
                    if(data.currentStep === "sorry"){
                        nextButton.hide();
                    }
                });
        });
    </script>

I have no experience with codeigniter, but as this is "just javascript" I would imagine that it should be a non-issue.

I hope this helps.

jonferguson commented 12 years ago

No re-selection won't be needed. Thank you very much for your swift reply, i'll test this out but this looks great, i'm sure it'll work perfectly.