$(document).ready(function () { //dynamicaly adjusts size of multi-line field based on amount of text $('.autoadjust textarea').each(function () { h(this); }).on('keydown blur change',function () { h(this); }); function h(e) { $(e).css({'height':'auto','overflow-y':'hidden'}).height(e.scrollHeight); } // Hide the real Submit button from the page: $(".Submit").hide(); // Open the Confirmation Dialog when the "Pre-Submit" button is pressed (actual submit button is hidden)" // Display them by adding the "Opened" class to the WindowShade and ConfirmationDialog objects. The CSS // above is what actually causes them to display after the class is added. $(".pre-submit").on("click",function(){ $("#WindowShade").addClass("Opened"); $("#ConfirmationDialog").addClass("Opened"); }); //Submit the form if the user presses the No button on the confirmation. $("#ConfirmationDialog .confirm-yes").on("click",function() { $("#WindowShade").removeClass("Opened"); $("#ConfirmationDialog").removeClass("Opened"); $(".Submit").trigger("click"); }); //Allow the user to continue making changes if they press Yes. $("#ConfirmationDialog .confirm-no").on("click",function() { $("#WindowShade").removeClass("Opened"); $("#ConfirmationDialog").removeClass("Opened"); }); //Show/Hide/ReadOnly sections based on stepid if ($('input[name="stepid"]').val() == "12") { //SIU $('.busHideCheck input').prop('checked', false).change(); //Unhide SIU section $('.uaaHideCheck input').prop('checked', true).change(); //Hide Prison/Unit section $('.l2uaaHideCheck input').prop('checked', true).change(); //Hide L2 Unit section $('.drHideCheck input').prop('checked', true).change(); //Hide Director section } else if ($('input[name="stepid"]').val() == "112") { //Prison $('.busHideCheck input').prop('checked', true).change(); //Hide SIU section $('.l2uaaHideCheck input').prop('checked', true).change(); //Hide L2 Unit section $('.drHideCheck input').prop('checked', true).change(); //Hide Director section //Clear Unit fields in case Not My Unit was selected //$('.clearUnit input, .clearUnit textarea, .clearUnit select').each(function() {clearSection($(this), true);}); } else if ($('input[name="stepid"]').val() == "30") { //Unit $('.busHideCheck input').prop('checked', false).change(); //Unhide SIU section $('.uaaHideCheck input').prop('checked', false).change(); //Unhide Unit section $('.l2uaaHideCheck input').click(); //Hide L2 Unit section $('.drHideCheck input').click(); //Hide Director section $('#q52 input, #q52 textarea').each(function() {setReadOnly($(this), true);}); //Read Only SIU section //Clear Unit fields in case Not My Unit was selected //$('.clearUnit input, .clearUnit textarea, .clearUnit select').each(function() {clearSection($(this), true);}); } else if ($('input[name="stepid"]').val() == "102") { //L2 Unit $('.busHideCheck input').prop('checked', false).change(); //Unhide SIU section $('.uaaHideCheck input').prop('checked', false).change(); //Unhide Unit section $('.l2uaaHideCheck input').prop('checked', false).change(); //Unhide L2 Unit section $('.drHideCheck input').prop('checked', true).change(); //Hide Director section $('#q52 input, #q52 textarea').each(function() {setReadOnly($(this), true);}); //Read Only SIU section $('#q57 input, #q57 textarea').each(function() {setReadOnly($(this), true);}); //Read Only Unit/Prison section //Clear L2 Unit fields in case Not My Unit was selected //$('.clearUnit input, .clearUnit textarea, .clearUnit select').each(function() {clearSection($(this), true);}); } else if (($('input[name="stepid"]').val() == "80") && ($('#q64 input').val() == "")){ //Director (No L2 Unit step) $('.busHideCheck input').prop('checked', false).change(); //Unhide SIU section $('.uaaHideCheck input').prop('checked', false).change(); //Unhide Unit/Prison section $('.uaaHideCheck input').prop('checked', false).change(); //Unhide Director section $('.drHideCheck input').prop('checked', false).change(); //Unhide Director section $('.l2uaaHideCheck input').prop('checked', true).change(); //Hide L2 Unit section $('#q52 input, #q52 textarea').each(function() {setReadOnly($(this), true);}); //Read Only SIU section $('#q57 input, #q57 textarea').each(function() {setReadOnly($(this), true);}); //Read Only Unit/Prison section //Clear Director fields in case Not My Unit was selected //$('.clearDirector input, .clearDirector textarea, .clearDirector select').each(function() {clearSection($(this), true);}); } else if (($('input[name="stepid"]').val() == "80") && ($('#q64 input').val() != "")) { //Director (With L2 Unit step) $('.busHideCheck input').prop('checked', false).change(); //Unhide SIU section $('.uaaHideCheck input').prop('checked', false).change(); //Unhide Unit/Prison section $('.l2uaaHideCheck input').prop('checked', false).change(); //Unhide L2 Unit section $('.drHideCheck input').prop('checked', false).change(); //Unhide Director section $('#q52 input, #q52 textarea').each(function() {setReadOnly($(this), true);}); //Read Only SIU section $('#q57 input, #q57 textarea').each(function() {setReadOnly($(this), true);}); //Read Only Unit/Prison section $('#q63 input, #q63 textarea').each(function() {setReadOnly($(this), true);}); //Read Only L2 Unit section //Clear Director fields in case Not My Unit was selected //$('.clearDirector input, .clearDirector textarea, .clearDirector select').each(function() {clearSection($(this), true);}); } else { $('#q52 input').prop('checked', false).change(); //Unhide SIU section $('#q57 input').prop('checked', false).change(); //Unhide Unit/Prison section $('#q63 input').prop('checked', false).change(); //Unhide L2 Unit section $('#q69 input').prop('checked', false).change(); //Unhide Director section } //Set Read Only function function setReadOnly(e,t){ if(t){ // Set input element to read-only e.attr({'disabled': 'True', 'backend-readonly': 'True', 'readonly': 'True'}); } else { // Remove readonly from input element e.removeAttr('readonly backend-readonly'); } } //Clear Section when Not My Unit is selected & resubmitted function clearSection(f,r){ if(r){ // Clear input element f.val(""); f.prop('required', false); f.prop('checked', false); } else { // Do nothing } } if ($('input[name="stepid"]').val() == "30") { $('.clearUnit input, .clearUnit textarea, .clearUnit select').each(function() {clearSection($(this), true);}); } else if ($('input[name="stepid"]').val() == "112") { $('.clearUnit input, .clearUnit textarea, .clearUnit select').each(function() {clearSection($(this), true);}); } else if ($('input[name="stepid"]').val() == "102") { $('.clearL2Unit input, .clearL2Unit textarea, .clearL2Unit select').each(function() {clearSection($(this), true);}); } else if ($('input[name="stepid"]').val() == "80") { $('.clearDirector input, .clearDirector textarea, .clearDirector select').each(function() {clearSection($(this), true);}); } else { //do nothing } });