я пропускаю проверку при переходе назад — SmartWizard

Я использую Jquery SmartWizard ссылка на сайт, Мне нужно остановить проверку, когда пользователь нажимает кнопку «Предыдущий» на любом шаге (по умолчанию на 1-м шаге кнопка «Предыдущий» отключена), кроме 1-го шага.

Вот мой код JavaScript

$(document).ready(function () {
// Smart Wizard
$('#wizard').smartWizard({
transitionEffect: 'fade',
onLeaveStep: leaveAStepCallback,
onFinish: onFinishCallback,
enableFinishButton: false
});

function leaveAStepCallback(obj) {
var step_num = obj.attr('rel');
return validateSteps(step_num);
}

function onFinishCallback() {
if (validateAllSteps()) {
$('form').submit();
}
}
});

function validateAllSteps() {
var isStepValid = true;
if (validateStep1() == false) {
isStepValid = false;
$('#wizard').smartWizard('setError', {
stepnum: 1,
iserror: true
});
} else {
$('#wizard').smartWizard('setError', {
stepnum: 1,
iserror: false
});
}
if (validateStep2() == false) {
isStepValid = false;
$('#wizard').smartWizard('setError', {
stepnum: 2,
iserror: true
});
} else {
$('#wizard').smartWizard('setError', {
stepnum: 2,
iserror: false
});
}
if (validateStep3() == false) {
isStepValid = false;
$('#wizard').smartWizard('setError', {
stepnum: 3,
iserror: true
});
} else {
$('#wizard').smartWizard('setError', {
stepnum: 3,
iserror: false
});
}
if (!isStepValid) {
$('#wizard').smartWizard('showMessage', 'Please correct the errors in the steps and continue');
}
return isStepValid;
}

function validateSteps(step) {
var isStepValid = true;
// validate step 1
if (step == 1) {
if (validateStep1() == false) {
isStepValid = false;
$('#wizard').smartWizard('showMessage', 'Please correct the errors in step' + step + ' and click next.');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: true
});
} else {
$('#wizard').smartWizard('hideMessage');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: false
});
}
}
// validate step2
if (step == 2) {
if (validateStep2() == false) {
isStepValid = false;
$('#wizard').smartWizard('showMessage', 'Please correct the errors in step' + step + ' and click next.');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: true
});
} else {
$('#wizard').smartWizard('hideMessage');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: false
});
}
}
// validate step3
if (step == 3) {
if (validateStep3() == false) {
isStepValid = false;
$('#wizard').smartWizard('showMessage', 'Please correct the errors in step' + step + ' and click next.');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: true
});
} else {
$('#wizard').smartWizard('hideMessage');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: false
});
}
}
return isStepValid;
}

function validateStep1() {
//Validation code here
}

function validateStep2() {
//Validation code here
}

function validateStep3() {
//Validation code here
}

0

Решение

…Очень разумная просьба. Попробуй это…

  function leaveAStepCallback(anchor, context) {
//var step_num = obj.attr('rel');
if(context.toStep > context.fromStep)
return validateSteps(fromStep);
else
return true;
}

документы Предположим, вы можете получить fromStep и toStep из второго параметра, как показано. Я надеюсь, что это так! Если нет, поищите его. Это должно быть где-то там.

0

Другие решения

Вы можете проверить как fromStep, так и toStep:

function nextStep(smartWizard, steps, context){
if(steps.fromStep == 1 && steps.toStep == 2){
// Do validations
}
}

Я использовал следующий мастер:

$('#wizard').smartWizard({
onLeaveStep: nextStep // triggers when leaving a step
});
0

По вопросам рекламы [email protected]