问题
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 & Exit</a></li>');
来源:https://stackoverflow.com/questions/24460458/how-to-add-a-reset-button-to-jquery-steps