$(document).ready(function () { HHAEnquiryForm.OnInitForm(); }); var HHAEnquiryForm = HHAEnquiryForm || {}; (function () { //consent validation state. var consentStateOn = false; //contact details validation state. var contactStateOn = false; var onInitForm = function () { //register change event handlers $("#mcm_onbehalfofapplicant_1").change(function () { setContactFields(); }); $("#mcm_onbehalfofapplicant_0").change(function () { setContactFields(); }); $("#mcm_partyprovidingconsent").change(function () { setConsentFields(); }); //set the initial section state setContactFields(); setConsentFields(); //start the form at the top setTimeout(() => { window.focus(); document.activeElement.blur(); $('html,body').scrollTop(0); }, 1500); }; var setConsentRequiredFields = function (setRequired) { if (setRequired) { PortalFormCommon.AddValidator("mcm_consentlegal2", "Information about any current legal issues is a required field."); PortalFormCommon.AddValidator("mcm_consentphysicalmentalhealth2", "Information about physical / mental health is a required field."); PortalFormCommon.AddValidator("mcm_consenteducationemploymenttraining2", "Information about education / employment training is a required field."); PortalFormCommon.AddValidator("mcm_personprovidingconsent", "The name of the person providing consent."); } else { PortalFormCommon.RemoveValidator("mcm_consentlegal2"); PortalFormCommon.RemoveValidator("mcm_consentphysicalmentalhealth2"); PortalFormCommon.RemoveValidator("mcm_consenteducationemploymenttraining2"); PortalFormCommon.RemoveValidator("mcm_personprovidingconsent"); } } var setContactRequiredFields = function (setRequired) { if (setRequired) { PortalFormCommon.AddValidator("mcm_contactname", "Contact name is required"); PortalFormCommon.AddValidator("mcm_contactrelationship", "Relationship to applicant is required"); PortalFormCommon.AddValidator("mcm_contactemail", "Contact email address is required"); PortalFormCommon.AddValidator("mcm_contactphone", "Contact phone number is required"); } else { PortalFormCommon.RemoveValidator("mcm_contactname"); PortalFormCommon.RemoveValidator("mcm_contactrelationship"); PortalFormCommon.RemoveValidator("mcm_contactemail"); PortalFormCommon.RemoveValidator("mcm_contactphone"); } } var showHideSection_ContactFields = function (visible) { PortalFormCommon.SetSectionVisible("tab_general_section_contact", visible); } var showHideSection_ConsentFields = function (visible) { PortalFormCommon.SetSectionVisible("tab_hha_section_consent", visible); } var setContactFields = function () { if ($("#mcm_onbehalfofapplicant_1").is(":checked") && contactStateOn == false) { contactStateOn = true; setContactRequiredFields(contactStateOn); showHideSection_ContactFields(contactStateOn); } if ($("#mcm_onbehalfofapplicant_0").is(":checked")) { contactStateOn = false; setContactRequiredFields(contactStateOn); showHideSection_ContactFields(contactStateOn); } } var setConsentFields = function () { let consentPartyVal = $("#mcm_partyprovidingconsent").val(); if (consentPartyVal != "803970002" && consentStateOn == false) { consentStateOn = true; setConsentRequiredFields(consentStateOn); showHideSection_ConsentFields(consentStateOn); } else if (consentPartyVal == "803970002") { consentStateOn = false; setConsentRequiredFields(consentStateOn); showHideSection_ConsentFields(consentStateOn); } } var setOnBehalfOfApplicantRequiredFields = function () { if ($("#mcm_onbehalfofapplicant_1").is(":checked") && contactStateOn == false) { consentStateOn = true; PortalFormCommon.AddValidator("mcm_contactname", "Contact name is required"); PortalFormCommon.AddValidator("mcm_contactrelationship", "Relationship to applicant is required"); PortalFormCommon.AddValidator("mcm_contactemail", "Contact email address is required"); PortalFormCommon.AddValidator("mcm_contactphone", "Contact phone number is required"); } if ($("#mcm_onbehalfofapplicant_0").is(":checked")) { consentStateOn = false; PortalFormCommon.RemoveValidator("mcm_contactname"); PortalFormCommon.RemoveValidator("mcm_contactrelationship"); PortalFormCommon.RemoveValidator("mcm_contactemail"); PortalFormCommon.RemoveValidator("mcm_contactphone"); } } /** * Public Members */ this.OnInitForm = onInitForm; this.SetOnBehalfOfApplicantRequiredFields = setOnBehalfOfApplicantRequiredFields; }).apply(HHAEnquiryForm);