function hideField(fieldName) { $('#' + fieldName).closest('td').hide(); } function showField(fieldName) { $('#' + fieldName).closest('td').show(); } //Conditional Fields Validation function makeRequired(fieldName, errorFieldLabel = "") { if ($("#" + fieldName) != undefined) { // Create new validator var Requiredvalidator = document.createElement('span'); Requiredvalidator.style.display = "none"; Requiredvalidator.id = fieldName + "Validator"; Requiredvalidator.controltovalidate = fieldName; if (errorFieldLabel == "") errorFieldLabel = $("#" + fieldName + "_label").html(); Requiredvalidator.errormessage = "'" + errorFieldLabel + "' is a required field."; Requiredvalidator.initialvalue = ""; // if this is a radio button field var $radios = $("#" + fieldName + " input[type='radio']"); if ($radios.length) { Requiredvalidator.evaluationfunction = function () { var selected = $("#" + fieldName + " input[type='radio']:checked"); return selected.length > 0; } } // otherwise, validate that value is not null else { Requiredvalidator.evaluationfunction = function () { var value = $("#" + fieldName).val(); if (value == null || value == "") { return false; } else { return true; } } } $("#" + fieldName).closest('.control').prev().addClass('required'); }; // Add the new validator to the page validators array: Page_Validators.push(Requiredvalidator); } function RemoveValidators(fields) { fields.forEach(function (field) { // 1) Remove any validators registered for this field if (window.Page_Validators && Array.isArray(Page_Validators)) { for (var i = Page_Validators.length - 1; i >= 0; i--) { var v = Page_Validators[i]; if (!v) continue; var targets = v.controltovalidate === field || v.controltovalidate === field + "_name" || // lookup visible input (v.id && (v.id === field + "Validator" || v.id.indexOf(field) === 0)); if (targets) Page_Validators.splice(i, 1); } } // 2) Strip HTML5/unobtrusive required flags from the actual inputs var $elems = $( "#" + field + ", " + "#" + field + "_name, " + // lookup text box "input[type='radio'][name='" + field + "']" // radio group ); $elems .prop("required", false) .removeAttr("required aria-required data-val data-val-required") .removeClass("input-validation-error") .removeData("val"); // 3) Remove visual required markers on labels $("#" + field + "_label").removeClass("required").find(".required").remove(); $("label[for='" + field + "'], label[for='" + field + "_name']") .removeClass("required").find(".required").remove(); // Some portal templates add 'required' on the heading before .control $("#" + field).closest(".control").prev().removeClass("required"); $("#" + field + "_name").closest(".control").prev().removeClass("required"); }); } function ConditionalVisibility({ fieldName, eventField, evaluationField, conditionalValue, clearValue = true, fieldRequired = false, operator = "=" }) { $("#" + eventField).change(function () { // Hide by Default hideField(fieldName, "text"); RemoveValidators([fieldName]); let evalVal = $("#" + evaluationField).val(); let conditionMet = false; if (operator === "=") { conditionMet = evalVal == conditionalValue; } else if (operator === "in") { if (Array.isArray(conditionalValue)) { conditionMet = conditionalValue.includes(evalVal); } else { console.error("ConditionallyVisibleAndRequired: " + fieldName + ": For 'in' operator, conditionalValue must be an array"); } } if (conditionMet) { // show the field and make required showField(fieldName, "text"); if (fieldRequired) { makeRequired([fieldName]); } } else if (clearValue) { // otherwise we should clear the value ClearValue(fieldName); } }); $("#" + eventField).change(); } function ClearValue(fieldName) { // clear value $("#" + fieldName).val(''); // text $("#" + fieldName).siblings(".clearlookupfield").click(); // lookup $("#" + fieldName + " input[type=radio]").prop('checked', ''); // radio buttons // fire change $("#" + fieldName).change(); } function ElementConditionallyVisible(element, eventField, evaluationField, conditionalValue) { $("#" + eventField).change(function () { // Hide by Default $(element).hide(); if ($("#" + evaluationField).val() == conditionalValue) { $(element).show(); } }); $("#" + eventField).change(); } function RefreshSubgrid(id) { $("#" + id + " div:first").trigger("refresh"); } function SetLookupTooltip(fieldName, tooltip) { $("#" + fieldName).siblings(".btn.btn-default.launchentitylookup").attr("data-bs-original-title", tooltip); $("#" + fieldName).siblings(".btn.btn-default.launchentitylookup").attr("data-original-title", tooltip); $("#" + fieldName).siblings(".btn.btn-default.launchentitylookup").attr("title", tooltip); $("#" + fieldName).siblings(".btn.btn-default.launchentitylookup").attr("aria-label", tooltip); } function FormNextButton_EnableDisable(flag) { // Enable/Disable NextButton flag ? $("#NextButton").removeClass("disabled") : $("#NextButton").addClass("disabled"); } function CountSubgridRows(id) { return $("#" + id + " div:first .view-grid table tbody").children().length; } function EnableDisableRadioButtons(id, flag) { $("#" + id).children("input").prop('disabled', !flag); } function DisableSubgridSorting(id) { $("#" + id + " table thead tr th a").each(function () { // Remove OnClick and Propagation Events $(this).off("click").click(function (event) { event.preventDefault(); event.stopPropagation(); }); }); } function DisableListSorting() { $(".view-grid table thead tr th a").each(function () { // Remove OnClick and Propagation Events $(this).off("click").click(function (event) { event.preventDefault(); event.stopPropagation(); }); }); } function RemoveSubgridColumns(subgrid, columns) { // when the subgrid loads $("#" + subgrid + " .entity-grid.subgrid").on("loaded", function () { // for each column we want to remove columns.forEach(function (column) { let header = $("#" + subgrid + " .view-grid table thead tr th a[aria-label='" + column + "']").closest("th"); // if the header is present if (header.length) { let headerIndex = header.index(); // remove the header header.remove(); let rows = $("#" + subgrid + " .view-grid table tbody tr"); rows.each(function () { let row = $(this); // remove the data from this column row.find("td").eq(headerIndex).remove(); }); } }); }); } function RemoveFileDeleteAndChange(fieldname) { $("#" + fieldname).remove(); $("#" + fieldname + "_delete_button").remove(); }