【发布时间】:2016-11-23 15:51:53
【问题描述】:
我目前设置了一个表单向导,让客户在进入下一步之前成功完成每个步骤。当我的json中的成功键设置为false时,我无法弄清楚如何让它阻止用户转到下一页。我相信该项目正在使用引导向导插件。文档链接在这里。您可以在下面看到我试图阻止下一步进展到的地方,但无论如何它仍在推进。
https://github.com/VinceG/twitter-bootstrap-wizard
<script>
$("#pageOneSubmission").click(function() {
$.ajax({
type: "POST",
url: ...,
data:
{
...
},
dataType: JSON,
success: function(data) {
if (!data.success) {
console.log("Errors");
$('#orderForm').bootstrapWizard('disable', $('#step2').val());
} else {
console.log("No Errors");
$("#user-created-confirmation").html(data);
swal({
title: "Success!!",
text: "Your order & patient profile are saved!",
timer: 2500,
showConfirmButton: false,
type: "success"
});
}
},
error: function(jqXhr) {
if (jqXhr.status === 422) {
var err = JSON.parse(jqXhr.responseText);
// this wouldn't work cause your redirecting the page, the loop
// wouldn't loop...
// window.location = $('#orderForm').attr('action');
$.each(err, function(key, value) {
$('input [name="'+ key +'"]').next().append("<p>Test</p>");
});
}
}
}, function(){
setTimeout(function() {
})
});
});
<div class="wizard order-form" id="orderForm">
<div class="wizard-inner">
<div class="connecting-line"></div>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#step1" data-toggle="tab" aria-controls="step1" role="tab" title="Step 1">
<span class="round-tab">
<i class="glyphicon glyphicon glyphicon-scale"></i>
</span>
</a>
</li>
<li role="presentation" class="disabled">
<a href="#step2" data-toggle="tab" aria-controls="step2" role="tab" title="Step 2">
<span class="round-tab">
<i class="glyphicon glyphicon glyphicon-user"></i>
</span>
</a>
</li>
<li role="presentation" class="disabled">
<a href="#step3" data-toggle="tab" aria-controls="step3" role="tab" title="Step 3">
<span class="round-tab">
<i class="glyphicon glyphicon glyphicon-edit"></i>
</span>
</a>
</li>
<li role="presentation" class="disabled">
<a href="#complete" data-toggle="tab" aria-controls="complete" role="tab" title="Complete">
<span class="round-tab">
<i class="glyphicon glyphicon-ok"></i>
</span>
</a>
</li>
</ul>
</div>
<div class="tab-content">
<div class="tab-pane active step" role="tabpanel" id="step1">
@include('pages.order.stepone')
</div>
<div class="tab-pane" role="tabpanel" id="step2">
@include('pages.order.steptwo')
</div>
<div class="tab-pane" role="tabpanel" id="step3">
@include('pages.order.stepthree')
</div>
<div class="tab-pane" role="tabpanel" id="complete">
<h3>Complete</h3>
<p>You have successfully completed all steps.</p>
</div>
<div class="clearfix"></div>
</div>
</div>
【问题讨论】:
标签: javascript jquery ajax twitter-bootstrap