0

I have created wizard which is not working as expected. it always shows 1st and 2nd wizard step. But I want only one wizard and then when click on Next, 2nd wizard should display and same way for 3rd. At last, I want to implement previous and submit.

Script

$(function ()
{

    $(".wizard-step:first").fadeIn();   
    $("#back-step").hide().click(function ()
    {
        var $step = $(".wizard-step:visible"); 
        if ($step.prev().hasClass("wizard-step")) { 
            $step.hide().prev().fadeIn();                 
            if (!$step.prev().prev().hasClass("wizard-step")) {
                $("#back-step").hide();
            }
        }
    });
    $("#next-step").click(function ()
    {
        var $step = $(".wizard-step:visible"); 
        var validator = $("form").validate(); 
        var anyError = false;
        $step.find("input").each(function ()
        {
            if (!validator.element(this)) { 
                anyError = true;
            }

        });

        if (anyError)
            return false; 

        if ($step.next().hasClass("confirm")) { 
            $.post("/wizard/confirm", $("form").serialize(), function (r)
            {
                $(".wizard-step.confirm").html(r);
            });
        }

        if ($step.next().hasClass("wizard-step")) { 
            $step.hide().next().fadeIn();  
            $("#back-step").show();  
        }
        else { 
            $("form").submit();
        }
    });
});

View

 <div class="Wizard-step">
        <div class="panel panel-default">
            <h4>BASIC INFO</h4>
            <div class="panel-body">
                <div class="form-group has-success ">
                    @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
                            <span class="input-group-addon"><i class="glyphicon glyphicon-ok"></i></span>
                        </div>
                        @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.EmailId, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.EmailId, new { htmlAttributes = new { @class = "form-control" } })
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>
                        @Html.ValidationMessageFor(model => model.EmailId, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.DOB, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.DOB, new { htmlAttributes = new { @class = "form-control" } })
                            <i class="glyphicon glyphicon-calendar"></i>
                        </div>

                        @Html.ValidationMessageFor(model => model.DOB, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">

                    <div class="CoursesStudiedYesNo" style="padding-left:6em;">
                        @Html.Label("Have you studied before?")
                        <br />
                        @Html.RadioButtonFor(m => m.StudiedYesNo, "Yes")<span id="SpacebetweenRadioandText">Yes</span><br />
                        @Html.RadioButtonFor(m => m.StudiedYesNo, "No", new { @checked = "checked" })<span id="SpacebetweenRadioandText">No</span>
                    </div>

                </div>
                <div class="form-group ">

                    <div class="CoursesDropdown" style="padding-left:6em;">
                        @Html.LabelFor(model => model.CoursesStudied, htmlAttributes: new { @class = "control-label " })
                        <br />
                        @Html.DropDownListFor(m => m.CoursesStudied, Model.CoursesStudiedList, "Choose the course you have studied here", new { @class = "form-control" })

                        @Html.ValidationMessageFor(model => model.CoursesStudied, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="wizard-step" style="display:none">
        <div class="panel panel-default">
            <h4>CONTACT DETAILS</h4>
            <div class="panel-body">
                <div class="form-group">
                    @Html.Label("Phone", htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.PhoneNumber, new { htmlAttributes = new { @class = "form-control" } })
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>

                        @Html.ValidationMessageFor(model => model.PhoneNumber, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    @Html.Label("Mobile", htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.mobileNumber, new { htmlAttributes = new { @class = "form-control" } })
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>

                        @Html.ValidationMessageFor(model => model.mobileNumber, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    @Html.Label("Address", htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.Street, new { htmlAttributes = new { @class = "form-control", placeholder = "Street" } })<br />
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.Suburb, new { htmlAttributes = new { @class = "form-control", placeholder = "Sub" } })<br />
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control", placeholder = "City" } })<br />
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.Region, new { htmlAttributes = new { @class = "form-control", placeholder = "Region" } })<br />
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>
                        <div class="inner-addon right-addon">
                            @Html.EditorFor(model => model.Country, new { htmlAttributes = new { @class = "form-control", placeholder = "Country" } })<br />
                            <i class="glyphicon glyphicon-ok"></i>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="wizard-step" style="display:none">
        <div class="panel panel-default">
            <h4>SELECT A COURSE</h4>
            <div class="panel-body">
                <div class="form-group">
                    @Html.Label("Course", htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.DropDownListFor(m => m.CourseName, Model.CourseNameList, "Choose a course", new { @class = "form-control" })
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="wizard-step" style="display:none">
        <div class="panel panel-default">
            <h4>SUMMARY</h4>
            <div class="panel-body">
                <div>
                    <dl class="dl-horizontal">
                        <dt>
                            @Html.DisplayNameFor(model => model.Name)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Name)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.EmailId)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.EmailId)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.DOB)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.DOB)
                        </dd>

                        <dt>
                            @Html.DisplayName("Study History")
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.CoursesStudied)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.PhoneNumber)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.PhoneNumber)
                        </dd>

                        <dt>
                            @Html.DisplayNameFor(model => model.mobileNumber)
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.mobileNumber)
                        </dd>

                        <dt>
                            @Html.DisplayName("Address")
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.Street)
                        </dd>

                        <dd>
                            @Html.DisplayFor(model => model.Suburb)
                        </dd>

                        <dd>
                            @Html.DisplayFor(model => model.City)
                        </dd>

                        <dd>
                            @Html.DisplayFor(model => model.Region)
                        </dd>

                        <dd>
                            @Html.DisplayFor(model => model.Country)
                        </dd>

                        <dt>
                            @Html.DisplayName("Selected Course")
                        </dt>

                        <dd>
                            @Html.DisplayFor(model => model.CourseName)
                        </dd>

                    </dl>
                </div>

            </div>
        </div>
    </div>
MVC
  • 649
  • 7
  • 23
  • Because `class="Wizard-step"` (uppercase `W`) is not `class="wizard-step"` –  Aug 06 '18 at 05:55
  • @StephenMuecke, Thank you so much. One more issue, I want to implement `submit` button in the last wizard. How can I do that. Currently, It is displaying in each wizard. – MVC Aug 06 '18 at 06:00
  • HTML class names are case-sensitive, [see here](https://stackoverflow.com/questions/12533926/are-class-names-in-css-selectors-case-sensitive). The submit button should be added outside `foreach` loop, without using predefined layout. – Tetsuya Yamamoto Aug 06 '18 at 06:02
  • Have a look at the code in [this answer](https://stackoverflow.com/questions/25643394/mvc-force-jquery-validation-on-group-of-elements/25645097#25645097) for a simpler implementation of a wizrd (and suggest you delete this and the main issue is just a typo) –  Aug 06 '18 at 06:02
  • @StephenMuecke, Thank you. your solution is really simple. It is working for me. I want to implement `previous` button as well. – MVC Aug 06 '18 at 06:16
  • Then just add a previous button :) - and all it need to do it hide the current section and display the previous section –  Aug 06 '18 at 06:17
  • @StephenMuecke, sorry to ask you. Can you please implement `previous` button in your given solution. please please. – MVC Aug 06 '18 at 06:28
  • Just add a `` and the the script is `$('.previous').click(function () { container.prev('.section').show().find('input').first().focus(); container.hide() });` –  Aug 06 '18 at 06:31
  • @StephenMuecke, the given code for previous button is not working – MVC Aug 06 '18 at 07:37
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/177467/discussion-between-stephen-muecke-and-mvc). –  Aug 06 '18 at 07:38

0 Answers0