jQuery(document).ready(($) => { $(".rform-button-submit").on("click", function (event) { event.preventDefault(); var form = $(this).closest("form"); var form_id = form.attr("data-form"); if (form.hasClass("rform-dsb")) { var m = form.find(".require-login"); m.css("display", "block"); } else { form.find(".rform-select").each(function () { if ($(this).is("[required]")) { var value = $(this) .closest(".rform-select-container") .find(".rform-select-input") .val(); if (value === "") { $(this).attr("aria-invalid", "true"); } else { $(this).attr("aria-invalid", "false"); } } }); // RADIO form.find(".rform-input[type=radio][required]").each(function () { $(this).on("change", function () { const groupName = $(this).attr("name"); form .find(`.rform-input[type=radio][name="${groupName}"]`) .attr("aria-invalid", "false"); }); }); // CHECKBOX let checkbox = form.find(".rform-checkbox-button[required]"); if (checkbox.length) { checkbox.each(function () { const $checkbox = $(this); const min = parseInt($checkbox.data("min")) || 1; const max = $checkbox.data("max") ? parseInt($checkbox.data("max")) : null; const groupName = $checkbox .find(".rform-input[type=checkbox]") .attr("name"); const group = $checkbox.find( `.rform-input[type=checkbox][name="${groupName}"]` ); validateGroup(); // validasi awal function validateGroup() { const checkedCount = group.filter(":checked").length; const isValid = max !== null ? checkedCount >= min && checkedCount <= max : checkedCount >= min; group.each(function () { $this = $(this); $this.attr("aria-invalid", ! isValid ? "true" : "false"); // console.log($this.attr('aria-invalid')); }); } group.on("change", validateGroup); }); } if (form[0].checkValidity()) { if (form.find("[aria-invalid=true]").length == 0) { // console.log('Form Valid'); $(this).prop("disabled", true); let current_html = $(this).html(); $(this).html( `