var PortalFormCommon = PortalFormCommon || {}; (function () { //eg. addValidator("customerid", "Customer") var addValidator = function (fieldName, fieldLabel) { if (typeof (Page_Validators) == 'undefined') return; // Create new validator $("#" + fieldName + "_label").parent().addClass("required"); var newValidator = document.createElement('span'); newValidator.style.display = "none"; newValidator.id = "RequiredFieldValidator" + fieldName; newValidator.controltovalidate = "casetypecode"; newValidator.errormessage = "" + fieldLabel + " is a mandatory field."; newValidator.validationGroup = ""; newValidator.initialvalue = ""; newValidator.evaluationfunction = function () { var value = $("#" + fieldName).val(); if (value == null || value == "") { return false; } else { return true; } }; // Add the new validator to the page validators array: Page_Validators.push(newValidator); // Wire-up the click event handler of the validation summary link $("a[href='#" + fieldName + "_label']").on("click", function () { scrollToAndFocus(fieldName + '_label', fieldName); }); }; //eg. removeValidator("customerid") var removeValidator = function (fieldName) { if (Page_Validators != undefined && Page_Validators.length > 0) { for (i = Page_Validators.length - 1; i >= 0; i--) { if (Page_Validators[i].id == "RequiredFieldValidator" + fieldName) { Page_Validators.splice(i, 1); } } } $("#" + fieldName + "_label").parent().removeClass("required"); }; var setSectionVisible = function(sectionName, visible) { try { var section = ".section[data-name='" + sectionName + "']"; if (visible) { $(section).closest('fieldset').show(); } else { $(section).closest('fieldset').hide(); } } catch (ex) { alert(ex); } } var removeMultiselectionOption = function (fieldName, optionValuesToRemove, retryCount = 0) { if (retryCount < 20) { //remove programs which are unavailable setTimeout(() => { //check if the control is on the form let controlContainer = $("#" + fieldName + "_Container"); if (controlContainer) { //find the list let itemList = controlContainer.find('ul.msos-selected-items'); if (itemList) { if (Array.isArray(optionValuesToRemove)) { optionValuesToRemove.forEach(option => { //find the items to remove let itemToRemove = itemList.find("[value=" + option + "]").closest("li.msos-option"); if (itemToRemove) { itemToRemove.remove(); console.log("Removing item: " + option); } } ) } else { //find the items to remove let itemToRemove = itemList.find("[value=" + optionValuesToRemove + "]").closest('li.msos-option'); if (itemToRemove) { itemToRemove.remove(); console.log("Removing item: " + optionValuesToRemove); } } let countItems = itemList.children().length; //find the label to upate let countLabel = controlContainer.find("#valuemsos-no-of-Items"); if (countLabel) { countLabel.text(countItems + " items"); } } else { //item list has not yet loaded try again. console.log("Trying to remove multi-selection items for " + fieldName + "..."); removeMultiselectionOption(fieldName, optionValuesToRemove, retryCount + 1); } } }, 100) } } /** * Public Members */ this.AddValidator = addValidator; this.RemoveValidator = removeValidator; this.SetSectionVisible = setSectionVisible; this.RemoveMultiselectionOption = removeMultiselectionOption; }).apply(PortalFormCommon);