function saveAndSubmitLogic(submitButtonField,fieldsToExclude,tabulated){ //debugger; var validationAlert = $(".validation-summary.alert.alert-error.alert-danger.alert-block"); if (validationAlert.is(":visible")) { submitButtonField.prop("checked", false); } var formId = $(".entity-form"); // add an required asterisk to each specified field (css visual only, does not actually enforce) formId.find(".form-control input-text-box, input[type='text'], textarea, select, input[type='checkbox'], input[type='url'], input[type='email'], input[type='radio']").each(function() { var fieldName var fieldLabel //var excludedIds = ["rsm_addressstreet2", "seafdn_additionalcomments", "rsm_copypreviousprojectsfields", "seafdn_additionalnotes", "seafdn_grantreportingfeedback", "seafdn_grantprogrammingfeedback", "seafdn_organizationalupdates", "seafdn_address2street2", "seafdn_agewhenyouarrivedintheusa", "seafdn_address1street2", "seafdn_fiscalsponsoraddressstreet2", "seafdn_otherdesiredlengthofdeferment", "seafdn_icouldntfindmyorganization", "seafdn_addressline2", "seafdn_applicantaddressstreet2", "rsm_additionalcomments", "rsm_comments", "seafdn_scholarshipoverview", "seafdn_otherareaofinterest", "rsm_schoolstateprovinceid_name"]; //var parsefieldsToExclude = JSON.parse(fieldsToExclude); var fieldsToExcludeArray = fieldsToExclude.slice(1, -1).split('", "'); var excludedIds = fieldsToExcludeArray; if(($(this).hasClass('msos-checkbox')) || ($(this).hasClass('ag-input-field-input')) || ($(this).is('select') && $(this).prop('multiple')) || ($(this).is("[data-date-format]"))){ return; } else if (($(this).hasClass('msos-input') && $(this).attr('id').indexOf('_ledit') !== -1) ){ currentId = this.id; fieldName = currentId.replace('_ledit', ''); fieldLabel = $("#"+ fieldName + "_label").html(); } else if (($(this).attr('readonly') !== undefined) && (!$(this).hasClass('text form-control lookup form-control'))) { return; } // else if (this.id == "rsm_addressstreet2" || this.id == "seafdn_additionalcomments" || this.id == "rsm_copypreviousprojectsfields" || this.id == "seafdn_additionalnotes" || this.id == "seafdn_grantreportingfeedback" || this.id == "seafdn_grantprogrammingfeedback"|| this.id == "seafdn_organizationalupdates"|| this.id == "seafdn_address2street2" || this.id == "seafdn_agewhenyouarrivedintheusa" || this.id == "seafdn_address1street2" || this.id == "seafdn_fiscalsponsoraddressstreet2" || this.id == "seafdn_otherdesiredlengthofdeferment" || this.id == "seafdn_icouldntfindmyorganization" || this.id == "seafdn_addressline2" || this.id == "seafdn_applicantaddressstreet2" || this.id == "rsm_additionalcomments" || this.id == "rsm_comments" || this.id == "seafdn_scholarshipoverview" || this.id == "seafdn_otherareaofinterest" || this.id == "rsm_schoolstateprovinceid_name"){ // return; // } else if ($(this).attr('id').indexOf('_name') !== -1) { currentId = this.id; fieldName = currentId.replace('_name', ''); fieldLabel = $("#"+ fieldName + "_label").html(); } else if ($(this).is(":radio")){ fieldName = $(this)[0].parentElement.id; fieldLabel = $('#'+$(this)[0].parentElement.id+'_label').html(); } else{ fieldName = this.id; fieldLabel = $("#"+ this.id + "_label").html(); } if (excludedIds.includes(fieldName)) { return; } addValidatorNew(fieldName, fieldLabel, function(val) { return requireFieldValidatorIfNotHidden(val, submitButtonField); }, tabulated); }); function requireFieldValidatorIfNotHidden(val,submitButtonField) { var control = val.ownerDocument.getElementById(val.controltovalidate); var submitButton1Checked = submitButtonField.is(':checked'); if (submitButton1Checked == false) return true; //if (control.offsetHeight < 1) return true; //if($(control).closest("td").css("display") == 'none') return true; if(($(control).closest("fieldset").css("display") == 'none') || ($(control).closest("td").css("display") == 'none')) return true; //if(submitButton1Checked == true && validationMessage) return true; //Use Existing RequiredField Validator return val.ownerDocument.defaultView.RequiredFieldValidatorEvaluateIsValid(val); } } function addSubmitButton(buttonText, submitButtonField){ // submit button logic //var submitButtonText = "Submit Application"; $($(".row.form-custom-actions .col-sm-6.clearfix")[1]).append("
"); var submitButton = document.querySelector("#NewSubmitButton"); submitButton.addEventListener("click", function(e){ //debugger; if ($("#NewSubmitButton").is('[disabled]')) { e.preventDefault(); return; } var saveButton = document.querySelector(".submit-btn"); //$("#cftb_applicationsubmitbutton_1").prop("checked", true); submitButtonField.prop("checked", true); saveButton.click(); var validationAlert = $(".validation-summary.alert.alert-error.alert-danger.alert-block"); if (validationAlert.is(":visible")) { //submitButtonField.prop("checked", false); // sets submit button back to no - have to replace the 1 with the 0 because 1 is yes and 0 is no var submitButtonNoId = submitButtonField.attr('id').replace('_1', '_0'); var submitButtonNo = $("#" + submitButtonNoId); submitButtonNo.prop("checked", true); } }); } // put tabs in an array var tabs = []; function moveTab(direction) { var hashValue = window.location.hash.split('#')[1]; console.log("Move direction " + direction); console.log("Current Hash " + hashValue); // if (hashValue == null) var indexVal = tabs.indexOf(hashValue); console.log("Location Number: " + indexVal); // update anchor/hash value in url // if the url is -1 (no hash value) set indexVal to first tab value (0) if (indexVal == -1) { indexVal = 0; } console.log("Location Number updated: " + indexVal); if (direction == 'next') { window.location.hash = tabs[indexVal+1]; } else if (direction == 'previous') { window.location.hash = tabs[indexVal-1]; } hideShowNavigation(hashValue); } function hideShowNavigation(hashValue) { var countOfTabs = $(".tab-title").length; // console.log(""); if (hashValue == null || hashValue == tabs[0]) { if(countOfTabs == 1){ $("#NewSubmitButton").show(); $("#previous-tab").hide(); $("#next-tab").hide(); } else{ $("#NewSubmitButton").hide(); $("#previous-tab").hide(); $("#next-tab").show(); } } else if (tabs.length-1 == tabs.indexOf(hashValue)) { $("#next-tab").hide(); $("#previous-tab").show(); $("#NewSubmitButton").show(); } else { $("#NewSubmitButton").hide(); $("#next-tab").show(); $("#previous-tab").show(); } } function addPreviousNext(hiddenTabs) { $(".tab-title").each(function (index) { tabs.push($(this).text().replaceAll(" ", "").replaceAll("/", "")); if (hiddenTabs.indexOf(tabs[index]) != -1) { // remove tab from array console.log("removing: " + tabs[index]); tabs.pop(); } }); var hashValue = window.location.hash.split('#')[1]; // console.log("hashValue: " + hashValue); // on load add previous and next plus hide the submitbutton $($(".row.form-custom-actions .col-sm-6.clearfix")[1]).append(""); $($(".row.form-custom-actions .col-sm-6.clearfix")[1]).append(""); // check if on first step or if on last step // if on first step hide previous // if on last step hide next and don't hide NewSubmiteButton hideShowNavigation(hashValue); } // submitOnlyLogic does the same as the saveAndSubmitLogic, but can be used when there is no save button and takes out the yes/no field check before validating. // on org profile page, scholarship and grant application intro page function submitOnlyLogic(fieldsToExclude) { var formId = $(".entity-form"); //debugger; formId.find(".form-control input-text-box, input[type='text'], textarea, select, input[type='checkbox'], input[type='url'], input[type='email'], input[type='radio']").each(function() { var fieldName, fieldLabel; var fieldsToExcludeArray = fieldsToExclude.slice(1, -1).split('", "'); var excludedIds = fieldsToExcludeArray; if(($(this).hasClass('msos-checkbox')) || ($(this).hasClass('ag-input-field-input')) || ($(this).is('select') && $(this).prop('multiple')) || ($(this).is("[data-date-format]"))){ return; } else if (($(this).hasClass('msos-input') && $(this).attr('id').indexOf('_ledit') !== -1) ){ currentId = this.id; fieldName = currentId.replace('_ledit', ''); fieldLabel = $("#"+ fieldName + "_label").html(); } //else if (($(this).attr('readonly') !== undefined) && (!$(this).hasClass('text form-control lookup form-control'))) { //return; //} // else if (this.id == "rsm_addressstreet2" || this.id == "seafdn_commentsonracialethnicmakeupoforganization" || this.id == "rsm_copypreviousprojectsfields" || this.id == "seafdn_address2street2" || this.id == "seafdn_address1street2" || this.id == "seafdn_fiscalsponsoraddressstreet2" || this.id == "rsm_additionalcomments" || this.id == "rsm_comments" || this.id == "seafdn_scholarshipoverview" || this.id == "seafdn_otherareaofinterest" || this.id == "rsm_schoolstateprovinceid_name"){ // return; // } else if ($(this).attr('id').indexOf('_name') !== -1) { currentId = this.id; fieldName = currentId.replace('_name', ''); fieldLabel = $("#"+ fieldName + "_label").html(); } else if ($(this).is(":radio")){ fieldName = $(this)[0].parentElement.id; fieldLabel = $('#'+$(this)[0].parentElement.id+'_label').html(); } else{ fieldName = this.id; fieldLabel = $("#"+ this.id + "_label").html(); } if (excludedIds.includes(fieldName)) { return; } addValidatorNew(fieldName, fieldLabel, function(val) { return requireFieldValidatorIfNotHidden(val); }); }); function requireFieldValidatorIfNotHidden(val) { var control = val.ownerDocument.getElementById(val.controltovalidate); if(($(control).closest("fieldset").css("display") == 'none') || ($(control).closest("td").css("display") == 'none')) return true; // Use Existing RequiredField Validator return val.ownerDocument.defaultView.RequiredFieldValidatorEvaluateIsValid(val); } }