#jquery #formvalidation.io
Вопрос:
У меня есть следующий код:
"use strict";
var KTCreateAccount = (function () {
var e,
t,
i,
o,
r,
s,
a = [];
return {
init: function () {
(t = document.querySelector("#kt_modal_create_account")) amp;amp; (e = new bootstrap.Modal(t)),
(i = document.querySelector("#kt_create_account_stepper")),
(o = i.querySelector("#kt_create_account_form")),
(r = i.querySelector('[data-kt-stepper-action="submit"]')),
(s = new KTStepper(i)).on("kt.stepper.next", function (e) {
console.log("stepper.next");
var t = a[e.getCurrentStepIndex() - 1];
t
? t.validate().then(function (t) {
console.log("validated!"),
"Valid" == t
? (e.goNext(), KTUtil.scrollTop())
: Swal.fire({
text: "Lo siento, hay errores que debe corregir.",
icon: "error",
buttonsStyling: !1,
confirmButtonText: "Ok, bien!",
customClass: { confirmButton: "btn btn-light" },
}).then(function () {
KTUtil.scrollTop();
});
})
: (e.goNext(), KTUtil.scrollTop());
}),
s.on("kt.stepper.previous", function (e) {
console.log("stepper.previous"), e.goPrevious(), KTUtil.scrollTop();
}),
a.push(
FormValidation.formValidation(o, {
fields: {
credito_ingreso_mensual: { validators: { notEmpty: { message: "Ingreso Mensual $" } } } ,
credito_antiguedad_trabajo: { validators: { notEmpty: { message: "Antigüedad en el Trabajo" } } },
credito_sindicato: { validators: { notEmpty: { message: "Sindicalización" } } },
credito_monto_solicitado: { validators: { notEmpty: { message: "Monto Solicitado" } } },
credito_plazo_solicitado: { validators: { notEmpty: { message: "Plazo Solicitado" } } },
credito_periocidad_pago: { validators: { notEmpty: { message: "Periocidad del Pago" } } },
credito_creditos_vigentes: { validators: { notEmpty: { message: "¿Actualmente tiene créditos vigentes?" } } },
credito_tipo: { validators: { notEmpty: { message: "Tipo de Crédito" } } },
credito_destino: { validators: { notEmpty: { message: "Especificar el destino del crédito (no descripciones generales)" } } },
credito_canal_pago: { validators: { notEmpty: { message: "Canal de Pago" } } },
credito_institucion_financiera_pago: { validators: { notEmpty: { message: "Institución Financiera donde se realizará el depósito de los recursos del crédito" } } },
credito_numero_sucursal_plaza: { validators: { notEmpty: { message: "Número de Sucursal y Plaza" } } },
credito_clabe: { validators: { notEmpty: { message: "CLABE" } } },
credito_numero_cta_bancaria_pagos: { validators: { notEmpty: { message: "Proporcione el número de la cuenta bancaria donde se depositarían los recursos origen del crédito que pudiera autorizarse" } } },
},
plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap: new FormValidation.plugins.Bootstrap5({ rowSelector: ".fv-row", eleInvalidClass: "", eleValidClass: "" }) },
})
),
a.push(
FormValidation.formValidation(o, {
fields: {
personal_ocupacion: { validators: { notEmpty: { message: "Ocupación" } } },
personal_identificacion_fiscal: { validators: { notEmpty: { message: "Número de Identificación Fiscal" } } },
personal_genero: { validators: { notEmpty: { message: "Género" } } },
personal_estudios: { validators: { notEmpty: { message: "Nivel Máximo de Estudios" } } },
personal_ciudad: { validators: { notEmpty: { message: "Ciudad" } } },
personal_estado: { validators: { notEmpty: { message: "Estado" } } },
personal_pais: { validators: { notEmpty: { message: "País" } } },
},
plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap: new FormValidation.plugins.Bootstrap5({ rowSelector: ".fv-row", eleInvalidClass: "", eleValidClass: "" }) },
})
),
a.push(
FormValidation.formValidation(o, {
fields: {
domicilio_calle: { validators: { notEmpty: { message: "Calle" } } },
domicilio_exterior: { validators: { notEmpty: { message: "No. Exterior" } } },
domicilio_colonia: { validators: { notEmpty: { message: "Colonia" } } },
domicilio_cp: { validators: { notEmpty: { message: "Código Postal" } } },
domicilio_ciudad: { validators: { notEmpty: { message: "Ciudad" } } },
domicilio_estado: { validators: { notEmpty: { message: "Estado" } } },
domicilio_pais: { validators: { notEmpty: { message: "País" } } },
},
plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap: new FormValidation.plugins.Bootstrap5({ rowSelector: ".fv-row", eleInvalidClass: "", eleValidClass: "" }) },
})
),
a.push(
FormValidation.formValidation(o, {
fields: {
contacto_calle: { validators: { notEmpty: { message: "Calle" } } },
contacto_exterior: { validators: { notEmpty: { message: "No. Exterior" } } },
contacto_colonia: { validators: { notEmpty: { message: "Colonia" } } },
contacto_cp: { validators: { notEmpty: { message: "Código Postal" } } },
contacto_ciudad: { validators: { notEmpty: { message: "Ciudad" } } },
contacto_estado: { validators: { notEmpty: { message: "Estado" } } },
contacto_pais: { validators: { notEmpty: { message: "País" } } },
},
plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap: new FormValidation.plugins.Bootstrap5({ rowSelector: ".fv-row", eleInvalidClass: "", eleValidClass: "" }) },
})
),
a.push(
FormValidation.formValidation(o, {
fields: {
terceros_dos: { validators: { notEmpty: { message: "Propietario Real" } } },
terceros_tres: { validators: { notEmpty: { message: "Datos del Proveedor del Recurso" } } },
terceros_nombre: { validators: { notEmpty: { message: "Nombre(s)" } } },
},
plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap: new FormValidation.plugins.Bootstrap5({ rowSelector: ".fv-row", eleInvalidClass: "", eleValidClass: "" }) },
})
),
r.addEventListener("click", function (t) {
t.preventDefault(),
(r.disabled = !0),
r.setAttribute("data-kt-indicator", "on"),
setTimeout(function () {
r.removeAttribute("data-kt-indicator"),
(r.disabled = !1),
Swal.fire({ text: "El formulario ha sido enviado correctamente!", icon: "success", buttonsStyling: !1, confirmButtonText: "Ok, bien!", customClass: { confirmButton: "btn btn-primary" } }).then(function (t) {
t.isConfirmed amp;amp; e amp;amp; e.hide();
});
}, 2e3);
});
},
};
})();
KTUtil.onDOMContentLoaded(function () {
KTCreateAccount.init();
});
Я хочу проверить поле terceros_dos (поле выбора), что если выбрано значение «MX», поле terceros_nombre обязательно, иначе оно не потребуется.
Я пробовал разными способами, но безуспешно, и теперь у меня другая проблема, последний шаг не проверен, как и другие четыре.
К вашему сведению: я прочитал следующий учебник https://formvalidation.io/guide/examples/enabling-validators-on-the-fly но я все равно заблудился.
Есть какие-нибудь зацепки? Спасибо за вашу помощь.