如何解决如果表单向导步骤中的字段未完成,则禁用下一步按钮
如果表单向导步骤中的字段未完成,我想禁用“下一步”按钮。我不知道 .step 对象的深度,我错过了这一步。这是我的代码:
//Sauvegarder les informations pour finaliser la création du compte de l'usager
$(".icons-tab-steps").steps({
headerTag: "h6",bodyTag: "fieldset",transitionEffect: "fade",titleTemplate: '<span class="step">#index#</span> #title#',labels: {
finish: submitButton,next: nextButton,prevIoUs: prevButton
},onFinished: function (event,currentIndex) {
$('body').addClass('loading');
var userName = $("#editRandomMp").find("#userName").val();
var vieuxMp = $("#viewMp").val();
var nouveauMp = $("#nouveauMp").val();
var urlDefaut = $("#pageAccueilSelect").val();
var jsonData = JSON.stringify({ userName: userName,vieuxMp: vieuxMp,nouveauMp: nouveauMp,urlDefaut: urlDefaut });
$.ajax({
contentType: 'application/json; charset=utf-8',dataType: 'json',type: 'POST',url: '/Compte/FinaliserCompte',data: jsonData,success: function (data,textStatus,jqXHR) {
if (data.code == 0) {
ModificationSucces(data);
}
else {
ModificationErreur(data);
}
},error: function (jqXHR,errorThrown) {
ModificationErreur({ code: jqXHR.status,message: ModalLabel.ErreurTechnique,data: [{ jqXHR: jqXHR,error: errorThrown }] });
}
});
}
});
更新//////////
通过挖掘,我找到了部分解决方案来帮助我做我想做的事情,如果它可以帮助其他人,我就把我的长代码放在这里。
//Paramètres pour le wizard form dans le modal #finaliserCompteModal
$(".icons-tab-steps").steps({
headerTag: "h6",onStepChanging: function (event,currentIndex,newIndex) {
currentStep = currentIndex;
if (newIndex < currentIndex) {
return true;
}
if (currentStep === 0) {
var txtOldPwd = $('#vieuxMp').val();
var txtPwd = $('#nouveauMp').val();
var txtPwdConfirm = $('#confirmMP').val();
var aLettres = new Array();
aLettres.push("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
var bValide = false;
var sMotPasse = txtPwd.toLowerCase();
// Vérification de l'alphanumérique
for (var i = 0; i < aLettres.length; i++) {
if (sMotPasse.indexOf(aLettres[i]) != -1) {
bValide = true;
i = aLettres.length + 1;
}
}
if (bValide) {
for (var i = 0; i <= 9; i++) {
if (sMotPasse.indexOf(i.toString()) != -1) {
bValide = true;
i = 10;
}
else { bValide = false; }
}
}
if (bValide) {
for (var i = 0; i < aLettres.length; i++) {
var reg = new RegExp("(" + aLettres[i] + ")","gi");
sMotPasse = sMotPasse.replace(reg,"");
}
for (var i = 0; i <= 9; i++) {
var reg = new RegExp("(" + i.toString() + ")","");
}
if (sMotPasse.length > 0) { bValide = false; }
}
if (txtOldPwd == "") {
alertMessage = "Entrez votre mot de passe actuel";
sweetAlertInput(alertMessage);
return false;
}
if (txtPwd == "") {
alertMessage = "Entrez un mot de passe";
sweetAlertInput(alertMessage);
txtPwd = txtPwdConfirm = "";
return false;
}
if (txtPwd.length < 6 || !bValide) {
alertMessage = "Le mot de passe doit contenir \nun minimum de 6 caractères (alphabétiques et numériques).\n\n* Exemple : 9c45Ep28";
sweetAlertInput(alertMessage);
txtPwd = txtPwdConfirm = "";
return false;
}
if (txtPwdConfirm == "") {
alertMessage = "Confirmez le mot de passe";
sweetAlertInput(alertMessage);
return false;
}
if (txtPwd != txtPwdConfirm) {
alertMessage = "La confirmation ne correspond pas avec le mot de passe";
sweetAlertInput(alertMessage);
return false;
}else {
return true;
}
}
if (currentStep === 1) {
if ($('#pageAccueilSelect').val()) {
return true;
}
}
else {
return false;
}
},currentIndex) {
//Sauvegarder les informations pour finaliser la création du compte de l'usager
var inputOk = true;
var userName = $("#finaliserCompteModal").find("#userName").val();
var vieuxMp = $("#finaliserCompteModal").find("#vieuxMp").val();
var nouveauMp = $("#finaliserCompteModal").find("#nouveauMp").val();
var urlDefaut = $("#finaliserCompteModal").find("#pageAccueilSelect").val();
var telephone = $("#finaliserCompteModal").find("#telephone").val();
var email = $("#finaliserCompteModal").find("#email").val();
var fonctionTravail = $("#finaliserCompteModal").find("#fonctionTravail").val();
var lieuTravail = $("#finaliserCompteModal").find("#lieuTravail").val();
var sexe = "";
if ($('input[name="sexe"]').is(':checked')) {
sexe = $("#finaliserCompteModal").find('input[name="sexe"]:checked').val();
}
if (telephone == "") {
alertMessage = "Entrez le numéro de téléphone";
sweetAlertInput(alertMessage);
return false;
}
if (email == "") {
alertMessage = "Entrez l'adresse de courrier électronique";
sweetAlertInput(alertMessage);
return false;
}
if (fonctionTravail == "") {
alertMessage = "Entrez la fonction de travail";
sweetAlertInput(alertMessage);
return false;
}
if (lieuTravail == "") {
alertMessage = "Entrez le lieu de travail";
sweetAlertInput(alertMessage);
return false;
}
if (sexe == "") {
alertMessage = "Sélectionnez le sexe";
sweetAlertInput(alertMessage);
return false;
}
if (inputOk) {
$('body').addClass('loading');
var userName = $("#finaliserCompteModal").find("#userName").val();
var vieuxMp = $("#finaliserCompteModal").find("#vieuxMp").val();
var nouveauMp = $("#finaliserCompteModal").find("#nouveauMp").val();
var urlDefaut = $("#finaliserCompteModal").find("#pageAccueilSelect").val();
var telephone = $("#finaliserCompteModal").find("#telephone").val();
var email = $("#finaliserCompteModal").find("#email").val();
var fonctionTravail = $("#finaliserCompteModal").find("#fonctionTravail").val();
var lieuTravail = $("#finaliserCompteModal").find("#lieuTravail").val();
var sexe = "";
if ($('input[name="sexe"]').is(':checked')) {
sexe = $("#finaliserCompteModal").find('input[name="sexe"]:checked').val();
}
var jsonData = JSON.stringify({ userName: userName,urlDefaut: urlDefaut,telephone: telephone,email: email,fonctionTravail: fonctionTravail,lieuTravail: lieuTravail,sexe: sexe });
$.ajax({
contentType: 'application/json; charset=utf-8',jqXHR) {
if (data.code == 0) {
var alerteMsg = "";
if (currentLang == "fr") {
alerteMsg = "Votre action a été complété avec succès";
} else {
alerteMsg = "Your action has been successfully completed";
}
$('body').removeClass('loading');
setTimeout(function () {
window.location.href = '' + data.message + ''
},3000);
sweetAlert({
title: '',text: '' + alerteMsg + '',timer: 3000,type: "success",showCancelButton: false,showConfirmButton: false
});
}
else {
ModificationErreur(data);
}
},errorThrown) {
ModificationErreur({ code: jqXHR.status,message: erreurTech,error: errorThrown }] });
}
});
}
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。