$("#unsubscribeReasonOther").click(function() { $("#customRadio6").prop("checked", true); switchReasonsWarning(false); }); $("#unsubscribeForm .unsubscribe-reason-save").click(function( event ) { if ($('#unsubscribeForm input[name="reason"]:checked').length == 0 || ($('#customRadio6').is(':checked') && !$("#unsubscribeReasonOther").val())) { event.preventDefault(); switchReasonsWarning(true); return false; } else { switchReasonsWarning(false); return true; } }); function switchReasonsWarning($show) { if ($show) { if ($('#unsubscribeForm input[name="reason"]:checked').length == 0) { $('.custom-control-label').addClass('label-warning'); } var warningWrapper = $("#reason-select-validation-warning"); warningWrapper.html('Please specify a reason'); warningWrapper.show(); } else { $("#reason-select-validation-warning").hide(); $('.custom-control-label').removeClass('label-warning'); } } $('#unsubscribeForm input[name="reason"]').click(function( event ) { switchReasonsWarning(false); }); $("#unsubscribeSubmitGroups").click(function( event ) { if (! validateSelectedGroups()) { event.preventDefault(); switchSelectGroupsWarning(true); return false; } else { switchSelectGroupsWarning(false); return true; } }); function validateSelectedGroups() { return $('.ml-group input[type="checkbox"]:checked').length > 0; } function switchSelectGroupsWarning($show) { if ($show) { $('.custom-control-label').addClass('label-warning'); var warningWrapper = $("#group-select-validation-warning"); warningWrapper.html('Please select at least one group'); warningWrapper.show(); } else { $('.custom-control-label').removeClass('label-warning'); $("#group-select-validation-warning").hide(); } } $('.ml-group input[type="checkbox"]').click(function() { switchSelectGroupsWarning(!validateSelectedGroups()); });