Search results

Create wizard using Tab

Tab items can be disabled initial control rendering by passing the boolean value to disabled property of TabItem class.

In the below Wizard sample, each Tab is integrated with required components to complete the reservation. Each field is provided with validation for all mandatory option to proceed to next tabs. Using Tab item’s template property the components are added into content.

Create the following contents for each tab in the wizard.

  1. Search tab: Created with [DropDownList] to select the source, destination and type of ticket. A [DatePicker] for choosing the date of journey.
  2. Train tab: Based on the selected start and end point, populated Grid with random list of available seats and train list. Initially define the columns and row selected event for validating, after the source and destination chosen update the [dataSource] for the Grid.
  3. Passenger tab: A table with Textbox, Numeric, DropDownList for adding passenger name, age, gender and preferred berth/seat. Add validation on entering passenger details to proceed.
  4. Payment tab: Calculate the ticket cost based on location, passenger count and ticket type. Generate data for Grid with passenger details, train number and ticket cost summary.

You can go back on each tab using buttons available in it and tabs are disabled to navigate through tab header click actions. Once you end the wizard all the data get cleared and wizard goes back to starting tab.

razor
wizard.cs
@using Syncfusion.EJ2.DropDowns
@using Syncfusion.EJ2.Navigations

<div class="e-tab-section">
    <div class="e-sample-resize-container">
        <div id="booking" style="display: none">
            <div class="wizard-title">Plan your journey</div>
            <div class="responsive-align">
                <div class="row">
                    <div class="col-xs-6 col-sm-6 col-lg-6 col-md-6 search-item">
                        @Html.EJS().DropDownList("startPoint").Placeholder("From").Width("100%").DataSource(
                              ViewBag.citiesData).Fields(new DropDownListFieldSettings { Text = "Name", Value = "Name" }).Render()
                    </div>
                    <div class="col-xs-6 col-sm-6 col-lg-6 col-md-6 search-item">
                        @Html.EJS().DropDownList("endPoint").Placeholder("To").Width("100%").DataSource(
                          ViewBag.citiesData).Fields(new DropDownListFieldSettings { Text = "Name", Value = "Name" }).Render()
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6 col-sm-6 col-lg-6 col-md-6 search-item">
                        @Html.EJS().DatePicker("date").Placeholder("Journey Date").Width("100%").Min("ViewBag.min").Max("ViewBag.max").Focus("showDate").Render()
                    </div>
                    <div class="col-xs-6 col-sm-6 col-lg-6 col-md-6 search-item">
                        @Html.EJS().DropDownList("quota").Placeholder("Ticket type").DataSource(
                              ViewBag.quota).Fields(new DropDownListFieldSettings { Text = "Text", Value = "Text" }).Render()
                    </div>
                </div>
                <div class="btn-container">
                    <button id="searchNext" class="e-btn">Search Train</button>
                </div>
                <span id="err1"></span>
            </div>
        </div>
        <div id="selectTrain" style="display: none">
            <div class="wizard-title">Select the train from the list </div>
            @(Html.EJS().Grid("availableTrain")
                .Columns(c =>
                {
                    c.Field("TrainNo").HeaderText("Train No").Width("120").Type("number").Add();
                    c.Field("Name").HeaderText("Name").Width("140").Add();
                    c.Field("Departure").HeaderText("Departure").Width("120").Add();
                    c.Field("Arrival").HeaderText("Arrival").Width("140").Add();
                    c.Field("Availability").HeaderText("Availability").Width("140").Type("number").Add();
                })
                .Width("100%")
                .RowSelected("trainSelected")
                .Render()
            )
            <br />
            <div class="btn-container">
                <button id="goToSearch" class="e-btn">Back</button>
                <button id="bookTickets" class="e-btn">Continue</button>
            </div>
            <span id="err2"></span>
        </div>
        <div id="details" style="display: none">
            <div class="details-page wizard-title">Enter the passenger details</div>
            <div id="PassengersList">
                <table id="passenger-table">
                    <colgroup>
                        <col />
                        <col />
                        <col />
                        <col />
                        <col />
                        <col />
                    </colgroup>
                    <thead>
                        <tr>
                            <th class="name-header">Name</th>
                            <th class="age-header">Age</th>
                            <th class="gender-header">Gender</th>
                            <th class="type-header">Berth Preference</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>
                                <input id="pass_name1" class="e-input" type="text" placeholder="Passenger Name">
                            </td>
                            <td>
                                @Html.EJS().NumericTextBox("pass_age1").Format("n0").Value(18).Min(1).Max(100).ShowSpinButton(false).Render()
                            </td>
                            <td>
                                @Html.EJS().DropDownList("pass_gender1").Text("Male").DataSource(ViewBag.gender).Fields(new DropDownListFieldSettings { Text = "Text", Value = "Text" }).Render()
                            </td>
                            <td>
                                @Html.EJS().DropDownList("pass_berth1").Placeholder("Optional").DataSource(ViewBag.berth).Fields(new DropDownListFieldSettings { Text = "Text", Value = "Text" }).Render()
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input id="pass_name2" class="e-input" type="text" placeholder="Passenger Name">
                            </td>
                            <td>
                                @Html.EJS().NumericTextBox("pass_age2").Format("n0").Value(18).Min(1).Max(100).ShowSpinButton(false).Render()
                            </td>
                            <td>
                                @Html.EJS().DropDownList("pass_gender2").Text("Male").DataSource(ViewBag.gender).Fields(new DropDownListFieldSettings { Text = "Text", Value = "Text" }).Render()
                            </td>
                            <td>
                                @Html.EJS().DropDownList("pass_berth2").Placeholder("Optional").DataSource(ViewBag.berth).Fields(new DropDownListFieldSettings { Text = "Text", Value = "Text" }).Render()
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input id="pass_name3" class="e-input" type="text" placeholder="Passenger Name">
                            </td>
                            <td>
                                @Html.EJS().NumericTextBox("pass_age3").Format("n0").Value(18).Min(1).Max(100).ShowSpinButton(false).Render()
                            </td>
                            <td>
                                @Html.EJS().DropDownList("pass_gender3").Text("Male").DataSource(ViewBag.gender).Fields(new DropDownListFieldSettings { Text = "Text", Value = "Text" }).Render()
                            </td>
                            <td>
                                @Html.EJS().DropDownList("pass_berth3").Placeholder("Optional").DataSource(ViewBag.berth).Fields(new DropDownListFieldSettings { Text = "Text", Value = "Text" }).Render()
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <br />
            <div class="btn-container">
                <button id="goBackToBook" class="e-btn">Back</button>
                <button id="confirmTickets" class="e-btn">Continue</button>
            </div>
            <span id="err3"></span>
        </div>
        <div id="confirm" style="display: none">
            <div class="tab-title1 wizardtitle">Confirm the details and proceed</div>
            @(Html.EJS().Grid("ticketDetailGrid")
                .Width("100%")
                .Columns(c =>
                {
                    c.Field("TrainNo").HeaderText("Train No").Width("120").Type("number").Add();
                    c.Field("PassName").HeaderText("Name").Width("120").Add();
                    c.Field("Gender").HeaderText("Gender").Width("120").Add();
                    c.Field("Berth").HeaderText("Berth").Width("120").Add();
                })
                .Render()
            )
            <br />
            <div id="amount"></div>
            <br />
            <div class="btn-container">
                <button id="goBackDetails" class="e-btn">Back</button>
                <button id="makePayment" class="e-btn">Pay</button>
            </div>
        </div>
        @(Html.EJS().Tab("ej2Tab")
            .HeightAdjustMode(HeightStyles.None)
            .Height("390")
            .Created("tabCreated")
            .Selecting("tabSelecting")
            .Items(new List<TabTabItem> {
                new TabTabItem { Header = ViewBag.headerTextOne, Content = ViewBag.content1 },
                new TabTabItem { Header = ViewBag.headerTextTwo, Content = ViewBag.content2 },
                new TabTabItem { Header = ViewBag.headerTextThree, Content = ViewBag.content3 },
                new TabTabItem { Header = ViewBag.headerTextFour, Content = ViewBag.content4 }
            })
            .Render()
        )
        <div>
            @Html.EJS().Dialog("alertDialog").Header("Success").Target("#ej2Tab").ShowCloseIcon(true).Width("250").IsModal(true).Created("dlgCreated").Visible(false).Render()
        </div>
    </div>
</div>

<script>
    var tabObj;
    var endPoint;
    var alertDlg;
    var locations;
    var ticketType;
    var startPoint;
    var journeyDate;
    var selectedTrain;
    var availTrainGrid;
    var ticketDetailGrid;

    var cities = [
        { name: "Chicago", fare: 300 },
        { name: "San Francisco", fare: 125 },
        { name: "Los Angeles", fare: 175 },
        { name: "Seattle", fare: 250 },
        { name: "Florida", fare: 150 }
    ];

    function tabCreated() {
        document.getElementById("searchNext").onclick = function (e) { tabNavigations(e); };
        document.getElementById("bookTickets").onclick = function (e) { tabNavigations(e); };
        document.getElementById("confirmTickets").onclick = function (e) { tabNavigations(e); };
        document.getElementById("makePayment").onclick = function (e) { tabNavigations(e); };
        document.getElementById("goToSearch").onclick = function (e) { tabNavigations(e); };
        document.getElementById("goBackToBook").onclick = function (e) { tabNavigations(e); };
        document.getElementById("goBackDetails").onclick = function (e) { tabNavigations(e); };

        tabObj = document.getElementById("ej2Tab").ej2_instances[0];
        startPoint = document.getElementById("startPoint").ej2_instances[0];
        endPoint = document.getElementById("endPoint").ej2_instances[0];
        ticketType = document.getElementById("quota").ej2_instances[0];
        journeyDate = document.getElementById("date").ej2_instances[0];
        availTrainGrid = document.getElementById("availableTrain").ej2_instances[0];
        ticketDetailGrid = document.getElementById("ticketDetailGrid").ej2_instances[0];
    }

    function showDate() {
        journeyDate = document.getElementById("date").ej2_instances[0];
        journeyDate.show();
    }

    function tabSelecting(e) {
        if (e.isSwiped) {
            e.cancel = true;
        }
    }

    function dlgCreated() {
        alertDlg = document.getElementById("alertDialog").ej2_instances[0];
        alertDlg.content = "Your payment successflly processed";
        alertDlg.buttons = [{
            buttonModel: { content: "Ok", isPrimary: true },
            click: function () {
                alertDlg.hide();
                tabObj.enableTab(0, true);
                tabObj.enableTab(1, false);
                tabObj.enableTab(2, false);
                tabObj.enableTab(3, false);
                tabObj.select(0);
            }
        }];
        alertDlg.dataBind();
        alertDlg.hide();
    }

    function trainSelected(args) {
        selectedTrain = args.data;
    }

    function filterTrains(args) {
        /* Generating trains based on source and destination chosen */
        var result = [];
        var fromCity = startPoint.text;
        var toCity = endPoint.text;
        var count = Math.floor((Math.random() * 3) + 2);
        for (var i = 0; i < count; i++) {
            var details = [];
            details.TrainNo = Math.floor((Math.random() * 20) + 19000);
            details.Name = "Train " + i;
            details.Departure = fromCity;
            details.Arrival = toCity;
            details.Availability = Math.floor((Math.random() * 20) + 20);
            result.push(details);
        }
        availTrainGrid.dataSource = result;
    }
    function finalizeDetails(args) {
        /* Get the passenger details and update table with name and other details for confirmation */
        var reserved = [];
        var passCount = 0;
        for (var i = 1; i <= 3; i++) {
            var name = document.getElementById("pass_name" + i);
            var berthSelected = document.getElementById("pass_berth" + i);
            var gender = document.getElementById("pass_gender" + i);
            if (name.value !== "") {
                var details = [];
                var berth = berthSelected.value;
                details.TrainNo = selectedTrain.TrainNo.toString();
                details.PassName = name.value;
                details.Gender = gender.value;
                details.Berth = (berth === "") ? "Any" : berth;
                reserved.push(details);
                passCount++;
            }
            var calcFare = 0;
            for (var i in cities) {
                if (startPoint.value == cities[i].name)
                    calcFare = calcFare + cities[i].fare;
                if (endPoint.value == cities[i].name)
                    calcFare = calcFare + cities[i].fare;
            }
            var displayAmt = document.getElementById("amount");
            if (ticketType.value === "Economy Class") {
                displayAmt.innerText = "Total payable amount: $" + passCount * (300 + calcFare)
            } else if (ticketType.value === "Business Class") {
                displayAmt.innerText = "Total payable amount: $" + passCount * (500 + calcFare)
            } else if (ticketType.value === "Common Class") {
                displayAmt.innerText = "Total payable amount: $" + passCount * (150 + calcFare)
            }
        }
        ticketDetailGrid.dataSource = reserved;
    }

    function tabNavigations(args) {
        switch (args.target.id) {
            case "searchNext":
                /* Validate the Source, Destination, Date and Class chosen and proceed only if all the fields are selected */
                if (!ej.base.isNullOrUndefined(startPoint.value) && !ej.base.isNullOrUndefined(endPoint.value) &&
                    !ej.base.isNullOrUndefined(ticketType.value) && !ej.base.isNullOrUndefined(journeyDate.value)) {
                    if (!ej.base.isNullOrUndefined(startPoint.value) && startPoint.value === endPoint.value) {
                        document.getElementById("err1").innerText = "* Arrival point can\"t be same as Departure";
                    }
                    else {
                        tabObj.enableTab(0, false);
                        tabObj.enableTab(1, true);
                        filterTrains(args);
                        tabObj.select(1);
                        document.getElementById("err1").innerText = "";
                        document.getElementById("err2").innerText = "";
                    }
                }
                else {
                    document.getElementById("err1").innerText = "* Please fill all the details before proceeding";
                }
                break;
            case "bookTickets":
                /* Based on the selected station generate Grid content to display trains available */
                if (availTrainGrid.getSelectedRecords() === undefined || availTrainGrid.getSelectedRecords().length === 0) {
                    document.getElementById("err2").innerText = "* Select your convenient train";
                }
                else {
                    tabObj.enableTab(2, true);
                    tabObj.select(2);
                    tabObj.enableTab(1, false);
                    document.getElementById("err2").innerText = "";
                }
                break;
            case "confirmTickets":
                /* Get the Passenger details and validate the fields must not be left empty */
                var name = document.getElementById("pass_name1");
                var age = document.getElementById("pass_age1");
                var gender = document.getElementById("pass_gender1");
                if (name.value === "" || age.value === "" || gender.value === "") {
                    document.getElementById("err3").innerText = "* Please enter passenger details";
                }
                else {
                    tabObj.enableTab(3, true);
                    tabObj.select(3);
                    tabObj.enableTab(2, false);
                    document.getElementById("err3").innerText = "";
                    finalizeDetails(args);
                }
                break;
            case "makePayment":
                alertDlg.show();
                break;
            case "goToSearch":
                /* Go back to change class, date or boarding places */
                selectedTrain = [];
                tabObj.enableTab(0, true);
                tabObj.select(0);
                tabObj.enableTab(1, false);
                break;
            case "goBackToBook":
                /* Change the preferred train chosen already */
                tabObj.enableTab(1, true);
                tabObj.select(1);
                tabObj.enableTab(2, false);
                break;
            case "goBackDetails":
                /* Update passenger detail before confirming the payment */
                tabObj.enableTab(2, true);
                tabObj.select(2);
                tabObj.enableTab(3, false);
                break;
        }
    }
</script>

<style>
    .e-content .e-item {
        font-size: 12px;
        margin: 10px;
    }

    #amount {
        text-align: right;
        font-size: 15px;
        padding: 15px 0px;
    }

    #passenger-table th {
        text-align: center;
        font-size: 14px;
        font-weight: 400;
        border: 1px solid gainsboro;
    }

    #passenger-table td,
    th {
        padding: 10px;
    }

    #passenger-table td {
        border: 1px solid gainsboro;
    }

    .name-header {
        width: 200px;
    }

    .age-header {
        width: 80px;
    }

    .gender-header {
        width: 120px;
    }

    .type-header {
        width: 150px;
    }

    .btn-container {
        text-align: center;
    }

    .search-item {
        padding-right: 50px;
        padding-bottom: 20px;
    }

    .item-title {
        font-weight: 500;
        padding-top: 10px;
    }

    @@media (max-width: 450px) {
        .e-sample-resize-container {
            height: 450px;
        }

        .responsive-align {
            width: 75%;
            margin: 0 auto;
        }

        .search-item {
            padding: 0 0 20px 0;
            width: 100%;
        }
    }

    #err1,
    #err2,
    #err3 {
        font-weight: bold;
        color: red;
        display: block;
        margin-top: 15px;
    }

    .wizard-title {
        font-size: 15px;
    }

    #PassengersList {
        overflow: auto;
    }

    #passenger-table {
        min-width: 500px;
        width: 100%;
    }

    .e-tab-section {
        padding: 0 15px;
    }
</style>
public ActionResult Index()
{
    List<DataFields> quotaData = new List<DataFields>();
    List<DataFields> genderData = new List<DataFields>();
    List<DataFields> berthData = new List<DataFields>();
    List<CitiesFields> citiesData = new List<CitiesFields>();

    quotaData.Add(new DataFields { ID = "1", Text = "Business Class" });
    quotaData.Add(new DataFields { ID = "2", Text = "Economy Class" });
    quotaData.Add(new DataFields { ID = "3", Text = "Common Class" });

    genderData.Add(new DataFields { ID = "1", Text = "Male" });
    genderData.Add(new DataFields { ID = "2", Text = "Female" });

    berthData.Add(new DataFields { ID = "1", Text = "Upper" });
    berthData.Add(new DataFields { ID = "2", Text = "Lower" });
    berthData.Add(new DataFields { ID = "3", Text = "Middle" });
    berthData.Add(new DataFields { ID = "4", Text = "Window" });
    berthData.Add(new DataFields { ID = "5", Text = "Aisle" });

    citiesData.Add(new CitiesFields { Name = "Chicago", Fare = 300 });
    citiesData.Add(new CitiesFields { Name = "San Francisco", Fare = 125 });
    citiesData.Add(new CitiesFields { Name = "Los Angeles", Fare = 175 });
    citiesData.Add(new CitiesFields { Name = "Seattle", Fare = 250 });
    citiesData.Add(new CitiesFields { Name = "Florida", Fare = 150 });

    ViewBag.headerTextOne = new TabHeader { Text = "New Booking" };
    ViewBag.headerTextTwo = new TabHeader { Text = "Train List" };
    ViewBag.headerTextThree = new TabHeader { Text = "Add Passenger" };
    ViewBag.headerTextFour = new TabHeader { Text = "Make Payment" };

    ViewBag.quota = quotaData;
    ViewBag.gender = genderData;
    ViewBag.berth = berthData;
    ViewBag.citiesData = citiesData;

    ViewBag.content1 = "#booking";
    ViewBag.content2 = "#selectTrain";
    ViewBag.content3 = "#details";
    ViewBag.content4 = "#confirm";

    ViewBag.min = DateTime.Now;
    ViewBag.max = DateTime.Now.AddMonths(3);

    return View();
}
public class DataFields
{
    public string ID { get; set; }
    public string Text { get; set; }
}
public class CitiesFields
{
    public string Name { get; set; }
    public int Fare { get; set; }
}