我目前在使用这两个插件进行 ajax 提交工作时遇到了一些麻烦,有人知道它应该是什么样子吗?因为现在它在没有 ajax 部分的情况下提交给 self - 与执行地址相同。我真的不知道 ajax 部分应该在哪里以及什么会触发 formvalidation.io 提交处理程序 - 因为我猜它应该从 on('success.form.fv') 调用
Formvalidation.io 部分
$('#orderForm').find('input[name="radioclient"]')
.on('ifChanged', function(e) {
// some conditionall validation
})
.end()
.formValidation({
... options ...
}).on('success.form.fv', function(e) {
// Prevent form submission
e.preventDefault();
var $form = $(e.target),
fv = $form.data('formValidation');
console.log('called');
});
燃料部分
$('#orderWizard')
// Call the wizard plugin
.wizard()
// Triggered when clicking the Next/Prev buttons
.on('actionclicked.fu.wizard', function(e, data) {
var fv = $('#orderForm').data('formValidation'), // FormValidation instance
step = data.step, // Current step
// The current step container
$container = $('#orderForm').find('.step-pane[data-step="' + step +'"]');
// Validate the container
fv.validateContainer($container);
var isValidStep = fv.isValidContainer($container);
if (isValidStep === false || isValidStep === null) {
// Do not jump to the target panel
console.log(isValidStep);
console.log(data);
e.preventDefault();
}
})
// Triggered when clicking the Complete button
.on('finished.fu.wizard', function(e) {
var fv = $('#orderForm').data('formValidation'),
step = $('#orderWizard').wizard('selectedItem').step,
$container = $('#orderForm').find('.step-pane[data-step="' + step +'"]');
// Validate the last step container
fv.validateContainer($container);
var isValidStep = fv.isValidContainer($container);
if (isValidStep === true) {
// Uncomment the following line to submit the form using the defaultSubmit() method
fv.defaultSubmit();
// Use Ajax to submit form data
// $("#loadersp").html('<center><img src="<?PHP echo base_url();?>assets/images/load.gif" alt="Czekaj" /></center>');
// $.ajax({
// type: "POST",
// url: "<?php echo site_url('Zlecenia/dodaj_zgloszenie'); ?>",
// data: new FormData(this),
// dataType: 'json',
// cache: false,
// }).success(function(response) {
// If there is error returned from server
// if (response.result === 'error') {
// $("#ajax_r").html('<div class="col-md-12"><div class="note note-danger"><h4 class="box-heading">Niepowodzenie</h4><p>'+response.msg+'</p></div></div>');
// $("html, body").animate({ scrollTop: 0 }, "slow");
// } else {
// $("#ajax_r").html('<div class="col-md-12"><div class="note note-success"><h4 class="box-heading">Powodzenie</h4><p>'+response+'</p></div></div>');
// $("html, body").animate({ scrollTop: 0 }, "slow");
// $('#nowyKlient').formValidation('resetForm', true);
// $("#nowyKlient").trigger('reset');
// }
// });
e.preventDefault();
// For testing purpose
// $('#thankModal').modal();
}
});