/** Mark field non required */ function makeNotRequired(fieldName) { try { if ($("#" + fieldName) != undefined) { $("#" + fieldName).removeAttr('required'); $.each(Page_Validators, function (index, validator) { if (validator && validator.id === fieldName + "Validator") { Page_Validators.splice(index, 1); } }); $("#" + fieldName + "_label").parent().removeClass("required"); } } catch (error) { console.log(error); } } /** Make field required. */ function makeRequired(fieldName) { try { if ($("#" + fieldName) != undefined) { //$("#" + fieldName).prop('required', true); $("#" + fieldName).closest(".control").prev().addClass("required"); // Create new validator var Requiredvalidator = document.createElement('span'); Requiredvalidator.style.display = "none"; Requiredvalidator.id = fieldName + "Validator"; Requiredvalidator.controltovalidate = fieldName; if(fieldName.includes("_datepicker_description")) { Requiredvalidator.errormessage = "" + $("#" + fieldName.replace("_datepicker_description", "") + "_label").html() + " is a required field."; } else { Requiredvalidator.errormessage = "" + $("#" + fieldName + "_label").html() + " is a required field."; } Requiredvalidator.initialvalue = ""; Requiredvalidator.evaluationfunction = function () { var control = $("#" + fieldName); if (control != undefined) { // check if picklist if(control.prop('class').includes('picklist horizontal') || control.prop('class').includes('picklist vertical')) { let valueSelected = false; $(`#${fieldName} :input`).each(function() { if($(this).prop('checked')) valueSelected =true; }); return valueSelected; } else if (control.prop('class').includes('boolean-radio')) { let valueSelected = false; if($('input[id="' + control + '_0"]:checked').val() === "0" || $('input[id="' + control + '_1"]:checked').val() === "1") { //Has Data valueSelected =true; } return valueSelected; } var value = $("#" + fieldName).val(); if (value == null || value == "") { return false; } else { return true; } } else { return true; } }; // check if validator exists let isExisting = false; $.each(Page_Validators, function (index, validator) { if (validator.id === fieldName + "Validator") { isExisting = true; } }); if (!isExisting) { // Add the new validator to the page validators array: Page_Validators.push(Requiredvalidator); } } } catch (error) { console.log(error); } } function setFieldRequired(fieldName, isRequired) { if (isRequired) { makeRequired(fieldName); } else { makeNotRequired(fieldName); } } function conditionalSection(sectionName, isVisible) { var childSection = $(`fieldset[aria-label='${sectionName}']`); if (isVisible) { childSection.show(); } else { childSection.hide(); } } function conditionalField(fieldName, isVisible) { var fieldControl = $(`#${fieldName}`); if (isVisible) { fieldControl.parent().parent().show(); } else { fieldControl.parent().parent().hide(); } } function showFormLoading(isLoading) { if (isLoading) { $(`div[class="container"]`).hide(); if ($(`#form_loading_animation`).length > 0) { $(`#form_loading_animation`).show(); } else { $('#mainContent').append($(`
`)); } } else { $(`div[class="container"]`).show() $(`#form_loading_animation`).hide(); } } //function formatBooleanOptions(booleanFieldName) { // var $set = $(`#${booleanFieldName}`).children(); // for(var i=0, len = $set.length; i < len; i+=2){ // $set.slice(i, i+2).wrapAll(``); // } // // swap the controls and labels // // the parent span with id _option_0 and _option_2 // // boolean yes and no to be swapped such that yes comes under _option_0 and no to _option_2 // $(`#${booleanFieldName}_option_0`).append($(`#${booleanFieldName}_1`)); // $(`#${booleanFieldName}_option_0`).append($(`label[for="${booleanFieldName}_1"]`)); // $(`#${booleanFieldName}_option_2`).append($(`#${booleanFieldName}_0`)); // $(`#${booleanFieldName}_option_2`).append($(`label[for="${booleanFieldName}_0"]`)); //} // //function formatReadOnlyBooleanField(booleanFieldName) { // // get the value // let boolValue = $(`#${booleanFieldName}_Value`).val() === '1' ? 'Yes' : 'No'; // $(`#${booleanFieldName}`).children().hide(); // $(`#${booleanFieldName}`).html(boolValue); //} function isProd() { const url = window.location.origin; return !(url.includes("dev-") || url.includes("uat-")); }