How to add a “reset” button to JQuery-steps

隐身守侯 提交于 2020-01-14 12:39:05

问题


I haven't seen this question asked - though I did read probably 100 jQuery-steps about similar topics - none seemed to solve my issue.

I'm using jQuery-steps and would like to add a "reset" button after the first step is completed - in case my user wants to clear the form and start over. I would like this button to be incerted after the default "next" button.

This is my current script based on the default basic form here

$(function ()
{

    function errorPlacement(error, element)
    {
        element.before(error);

    }
    $("#form").validate({
        rules: {
            zip: {
                required: true,
                maxlength:5,
                minlength:5
                },
            phone: {
                required: true,
                minlength: 10,
                phoneUS: true
            }

        }
    });


    $("#wizard").steps({
        headerTag: "h3",
        bodyTag: "section",
        transitionEffect: "slideLeft",
        onStepChanging: function (event, currentIndex, newIndex)
        {
            // Allways allow step back to the previous step even if the current step is not valid!
            if (currentIndex > newIndex)
            {
                return false;
            }


            $("#form").validate().settings.ignore = ":disabled,:hidden";
            return $("#form").valid();

        },
        onFinishing: function (event, currentIndex)
        {
            $("#form").validate().settings.ignore = ":disabled";
            return $("#form").valid();
        },
        onFinished: function (event, currentIndex)
        {
            alert("Thank you! Your request has been sumbitted.");
        }
    });
});

回答1:


You could enable and use the cancel button to call validator.resetForm(). See the following example:

$(function ()
{
    var validator;

    $("#wizard").steps({
        enableCancelButton: true,
        onCanceled: function (event)
        {
            validator.resetForm();
        }
    });

    validator = $("#form").validate({
        rules: {
            zip: {
                required: true,
                maxlength:5,
                minlength:5
            },
            phone: {
                required: true,
                minlength: 10,
                phoneUS: true
            }
        }
    });
});



回答2:


$form.find("[aria-label=Pagination]").append('<li class="" aria-disabled="true"><a class="imp-sub" href="#">Save &amp; Exit</a></li>');


来源:https://stackoverflow.com/questions/24460458/how-to-add-a-reset-button-to-jquery-steps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!