diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index dfd3687e..979fadb6 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -3610,28 +3610,39 @@ let hasEmptyInsurer = false; let firstEmptyField = null; + // $('select[name="follow_insurer_id[]"]').each(function() { + // const $field = $(this); + // const errorId = 'error-' + $field.attr('id'); + + // // Remove any old message + // $('#' + errorId).remove(); + + // if ($field.val().trim() === "") { + // hasEmptyInsurer = true; + // $field.addClass('is-invalid'); + + // // Add error message only once + // if (!$field.next('.text-danger').length) { + // $field.after(`This value is required.`); + // } + + // if (!firstEmptyField) { + // firstEmptyField = this; // store first empty field + // } + // } else { + // $field.removeClass('is-invalid'); + // $('#' + errorId).remove(); // remove if filled + // } + // }); $('select[name="follow_insurer_id[]"]').each(function() { - const $field = $(this); - const errorId = 'error-' + $field.attr('id'); - - // Remove any old message - $('#' + errorId).remove(); - - if ($field.val().trim() === "") { + if ($(this).val().trim() === "") { hasEmptyInsurer = true; - $field.addClass('is-invalid'); - - // Add error message only once - if (!$field.next('.text-danger').length) { - $field.after(`This value is required.`); - } - + $(this).addClass('is-invalid'); if (!firstEmptyField) { - firstEmptyField = this; // store first empty field + firstEmptyField = this; // store the first invalid field } } else { - $field.removeClass('is-invalid'); - $('#' + errorId).remove(); // remove if filled + $(this).removeClass('is-invalid'); } }); @@ -4570,7 +4581,7 @@ switch(index) { case 0: // Insurer selection newCell = ` - @@ -4783,11 +4794,11 @@ $('[name="standard_tp[]"]').val(std_tp); $('[name="standard_ter[]"]').val(std_tep); - if(insurerCount > 1){ - $('.follow_insurer').prop('required', true); - }else{ - $('.follow_insurer').prop('required', false); - } + // if(insurerCount > 1){ + // $('.follow_insurer').prop('required', true); + // }else{ + // $('.follow_insurer').prop('required', false); + // } }); @@ -4804,6 +4815,12 @@ // }); co_share_percentage_calculation(insurerCount, "add"); + + if (insurerCount === 0) { + $('.follow_insurer').prop('required', false); + } else { + $('.follow_insurer').prop('required', true); + } } function removeInsurerColumn(index, count_index) { @@ -4834,6 +4851,11 @@ insurer_count_array = insurer_count_array.filter(item => item !== count_index); co_share_percentage_calculation(null, "remove"); insurerCount--; + if (insurerCount === 0) { + $('.follow_insurer').prop('required', false); + } else { + $('.follow_insurer').prop('required', true); + } console.log('#################################### END Remove Insurer Column ####################################');