function Wiz(query) { return wizForms.getFieldByFieldID(query); } const wizForms = { getFieldByFieldID(fieldid) { var fieldIDs = []; var jQueryObjects = wizForms.getFieldsjQueryObjectsByFieldID(fieldid); $.each(jQueryObjects, function (i, currentObject) { fieldIDs.push(wizForms.jQueryObjectToWizObject(currentObject, fieldid)); }); if (fieldIDs.length > 1) return fieldIDs; else return fieldIDs[0]; }, jQueryObjectToWizObject(jQueryObject, fieldid) { var fieldType = wizForms.getFieldIDTypeByjQueryObject($(jQueryObject)); return { jQueryFieldObject: $(jQueryObject), fieldID: fieldid, type: fieldType, setValue(value) { wizForms.setFieldValueByType(this, value); }, getValue() { return wizForms.getFieldValueByType(this); }, getTextValue() { return wizForms.getFieldTextValueByType(this); }, hide() { if (fieldType == "multiFileUpload") { $(jQueryObject).parent().parent().css("display", "none"); } else if ($(jQueryObject).hasClass("checkBoxtitle")) { $(jQueryObject).css("display", "none"); } else { $(jQueryObject).parent().css("display", "none"); } }, show() { if (fieldType == "multiFileUpload") { $(jQueryObject).parent().parent().css("display", "inline-block"); } else if ($(jQueryObject).hasClass("checkBoxtitle")) { $(jQueryObject).css("display", "inline-block"); } else { $(jQueryObject).parent().css("display", "inline-block"); } }, setErrorMessage(errMsg) { $(jQueryObject).parent().find(".validError").text(errMsg); }, on(onType, onFunction) { switch (fieldType) { case "select": $(jQueryObject).find("select").on(onType, onFunction); break; case "textBox": $(jQueryObject).find("input").on(onType, onFunction); break; case "radio": $(jQueryObject).find("input").on(onType, onFunction); break; case "datePicker": $(jQueryObject).find("input").on(onType, onFunction); break; case "checkBox": $(jQueryObject).find("input").on(onType, onFunction); break; } }, getDateObject() { return wizForms.StringHebrewDateConvertToDateObject(wizForms.getFieldValueByType(this)); }, getFiles() { return wizForms.getFiles(fieldid); }, getOptions() { // Add casing for diff field types return wizForms.getOptions(this) }, showSpecificValues(values) { // Add casing for diff field types return wizForms.showDropDownValues(values, fieldid) }, showAllValues() { return wizForms.showAllDropDownValues(fieldid) }, disable() { return wizForms.disable(fieldid) }, enable() { return wizForms.enable(fieldid) } } }, getOptions(wizObject) { let type = wizObject.type let optionsArr = []; switch (type) { case "select": let options = wizObject.jQueryFieldObject.find("select option"); $(options).each(function () { optionsArr.push($(this).text()) }) break; } return optionsArr; }, getFiles(fieldid) { let files = []; let currentFilesArray; wizForms.getFieldsjQueryObjectsByFieldID(fieldid).parent().find(".mu_wrap_upload input").each(function () { currentFilesArray = $(this)[0].files; for (let i = 0; i < currentFilesArray.length; i++) { files.push(currentFilesArray[i]); } }) return files; }, addTopLogos(...logosLinks) { $(".formLogo").append(); }, setFieldValueByType(wizObject, value) { switch (wizObject.type) { case "textBox": wizObject.jQueryFieldObject.find("input").val(value); case "select": wizObject.jQueryFieldObject.find("select").val(value).change(); break; case "textArea": wizObject.jQueryFieldObject.find("textArea").val(value); break; case "checkBox": $(wizObject.jQueryFieldObject.find(`input[value='${value}']`)).prop("checked", true); break; case "radio": $(wizObject.jQueryFieldObject.find(`input[value='${value}']`)).prop("checked", true); break; case "datePicker": wizObject.jQueryFieldObject.find("input").val(value); break; } }, nestedFields: { setNestedFields(nestedFields) { if ("fatherValueToShow" in nestedFields != true) { hideNestedFields(nestedFields); } }, hideNestedFields(field) { for (const child of field.children) { if (child.children.length > 0) hideNestedFields(child) hideElems(child.fieldid) } } }, getFieldValueByType(wizObject) { switch (wizObject.type) { case "textBox": return wizObject.jQueryFieldObject.find("input").val(); case "select": return wizObject.jQueryFieldObject.find("select :selected").val(); case "textArea": return wizObject.jQueryFieldObject.find("textArea").val(); case "checkBox": var selectOptions = []; var options = $(wizObject.jQueryFieldObject.find(`input:checked`)); $.each(options, function (i, currentOption) { selectOptions.push(currentOption.value); }) return selectOptions; case "radio": return $(wizObject.jQueryFieldObject).find(`input:checked`).val(); case "datePicker": return wizObject.jQueryFieldObject.find("input").val(); } }, getFieldTextValueByType(wizObject) { switch (wizObject.type) { case "textBox": return wizObject.jQueryFieldObject.find("input").text(); case "select": return wizObject.jQueryFieldObject.find("select :selected").text(); case "textArea": return wizObject.jQueryFieldObject.find("textArea").text(); } }, getFieldIDTypeByjQueryObject(jQueryObject) { // jQueryObject=$(jQueryObject); if (jQueryObject.hasClass("textBox")) { return "textBox"; } if (jQueryObject.hasClass("textDate")) { return "datePicker"; } if (jQueryObject.hasClass("textRadio")) { return "radio"; } if (jQueryObject.children().hasClass("checkBoxtitle")) { return "checkBox"; } if (jQueryObject.hasClass("textSelect")) { return "select"; } if (jQueryObject.hasClass("textArea")) { return "textArea"; } if (jQueryObject.hasClass("headlineTitle")) { return "title"; } if (jQueryObject.parent().find(".mu_wrap_upload").length > 0) { return "multiFileUpload"; } }, getFieldsjQueryObjectsByFieldID(fieldid) { var currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textBox`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textDate`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textRadio`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textTitle`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textSelect`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .textArea`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}'] > .headlineTitle`); if (currentFields.length >= 1) return currentFields; currentFields = $(`[fieldid='${fieldid}']`); if (currentFields.length >= 1) return currentFields; else return null; }, //#region MandatoryFields loadMandatoryFieldCheckup() { wizForms.addStarToMandatoryFields(); wizForms.changeNextBTNToDiv(); wizForms.changeNextBTNOnClickToCheckMandatoryFields(); }, addStarToMandatoryFields() { let currentField; $(`.mandatory`).each(function () { if ($(this).attr("fieldid") != undefined) { currentField = Wiz($(this).attr("fieldid")); } else { currentField = Wiz($($(this).children()[0]).attr("fieldid")); } if (currentField.type != "multiFileUpload") { $(this).find("[class*='Title']:not('[for]')").prepend(`*`); } else { $(this).find(".textTitle").prepend(`*`); } }); }, changeNextBTNOnClickToCheckMandatoryFields() { let currentOnClick = ""; $(".nextBTN").each(function () { currentOnClick = $(this).attr("onclick").replace(";return false;", ""); if (currentOnClick.includes('checkMandatoryFields()') != true) { $(this).attr("onclick", `wizForms.checkMandatoryFields( "${currentOnClick}" )`); } }); }, changeNextBTNToDiv() { $(".nextBTN").each(function () { wizForms.changeElementType("nextBTN", "div") }); }, checkMandatoryFields(onSuccessFunction) { let currentFieldID = ""; let currentField; let allMandatoryFieldsFilled = true; //mandatory for normal fields $(`[id='page${currentPage}'] .mandatory`).not("[style*='display: none;']").each(function () { if ($(this).attr("fieldid") != undefined) { currentFieldID = $(this).attr("fieldid"); currentField = Wiz(currentFieldID); if (currentField.type != "multiFileUpload") { if (currentField.getValue() == undefined || currentField.getValue().length <= 0) { currentField.setErrorMessage("זהו שדה חובה"); allMandatoryFieldsFilled = false; } } } }); //mandatory for multiUploadFiles fields $(`[id='page${currentPage}'] .mandatory`).not("[style*='display: none;']").find("[fieldid]").find(".mu_wrap_upload").each(function () { currentFieldID = $(this).parent().attr("fieldid"); currentField = Wiz(currentFieldID); if (currentField.type == "multiFileUpload") { if (currentField.getFiles().length <= 0) { currentField.setErrorMessage("זהו שדה חובה"); allMandatoryFieldsFilled = false; } } //else if (currentField.getValue() == undefined || currentField.getValue().length <= 0) { // currentField.setErrorMessage("זהו שדה חובה"); //allMandatoryFieldsFilled = false; // } }); if (allMandatoryFieldsFilled == true) { eval(onSuccessFunction); } }, changeElementType(classTo, transformTo) { var attrs = {}; $.each($(`.${classTo}`)[0].attributes, function (idx, attr) { attrs[attr.nodeName] = attr.nodeValue; }); $(`.${classTo}`).replaceWith(function () { return $(`<${transformTo}/>`, attrs).append($(this).contents()); }); }, //#endregion //#region LimitFileUploads, limitFileUploads() { wizForms.checkFilesOnUpload(); wizForms.checkFilesOnRemove(); wizForms.displayUploadStats(); }, limitUploadSettings: { "allowedFileTypes": ["jpeg", "jpg", "png", "docx", "tif", "tiff", "bmp", "pdf", "pptx"], "maxMBAllowed": 10, "maxFilesAllowed": 10, uploadInfomration: { "currentFilesAmount": 0, "currentMBUploaded": 0 }, "reachedMaxFilesMessage": "שים לב! גודל הקבצים המצורפים עולה מגבלת הכמות של 10 קבצים ולכן לא ניתן לשלוח את הטופס", "reachedMaxMBMessage": "שים לב! גודל הקבצים המצורפים עולה על 10MB לכן לא ניתן לשלוח את הטופס", "bannedFileTypeMBMessage": "ניתן לצרף רק קבצים בפורמטים הבאים: .jpg .jpeg .pdf .doc .docx .png .tiff .bmp" }, checkFilesOnUpload() { var uploadFields = $("[fieldid*='upload']"); var currentSize = 0; var totalSize = 0; $(uploadFields).each(function () { $(this).find("input").attr("onChange", ""); $(this).on("change", function () { var validFileType = false; var file = $(this)[0].files; if ( file && file.length > 0 ) { var fileName = file[0].name; var fileExtension = fileName.split(".").pop().toLowerCase(); let fileSizeInMB = (file[0].size) / (1024 * 1024); totalSize = 0; currentSize = 0; if ((fileSizeInMB + wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded) > wizForms.limitUploadSettings.maxMBAllowed) { alert(wizForms.limitUploadSettings.reachedMaxMBMessage); $(this).val("") return; } for (let i = 0; i < wizForms.limitUploadSettings.allowedFileTypes.length; i++) { if (fileExtension == wizForms.limitUploadSettings.allowedFileTypes[i]) { validFileType = true; } } // If file is multiuploadfile, call addMultiFile function if ($(this).hasClass('mu_upload')) { addMultiFile(this); } if (validFileType == true) { for (var i = 0; i < this.files.length; i++) { currentSize = this.files[i].size; currentSize /= 1024 * 1024; totalSize += currentSize; wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount++; } wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded += totalSize; wizForms.checkFilesOnRemove(); wizForms.checkLimits(); wizForms.displayUploadStats(); } else { alert(wizForms.limitUploadSettings.bannedFileTypeMBMessage); $(this).val("") } } }); }); }, checkFilesOnRemove() { var uploadedFiles = $("[id^='upload_prev']"); var currentSize = 0; $(uploadedFiles).each(function () { $(this).children().each(function () { var currnetButton = $(this).find("input"); $(currnetButton).attr("onclick", ""); $(currnetButton).unbind(); $(currnetButton).on("click", function () { var currentInputId = $(this).parent().attr("name"); currentSize = $("#" + currentInputId)[0].files[0].size; currentSize /= 1024 * 1024; wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount--; wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded -= currentSize; wizForms.checkLimits(); removeFile(this) wizForms.displayUploadStats(); }); }) }); }, checkLimits() { var disableUpload = false; console.log(wizForms.limitUploadSettings.uploadInfomration); if (wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount >= wizForms.limitUploadSettings.maxFilesAllowed || wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded >= wizForms.limitUploadSettings.maxMBAllowed) { setTimeout(function () { $("[id^='fileToUpload']").attr("disabled", "true"); if (currentPage >= $("[id^='page']").length) { $("#finishForm").hide(); } }, 100); if (wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded >= wizForms.limitUploadSettings.maxMBAllowed) { alert(wizForms.limitUploadSettings.reachedMaxMBMessage); } } else { setTimeout(function () { $("[id^='fileToUpload']").removeAttr("disabled"); if (currentPage >= $("[id^='page']").length) { $("#finishForm").show(); } }, 100); } }, displayUploadStats() { $("[fieldid='upSummary']").html(`
כמות טפסים מצורפים היא ${wizForms.limitUploadSettings.uploadInfomration.currentFilesAmount}
גודל קבצים מצורפים: MB ${wizForms.limitUploadSettings.uploadInfomration.currentMBUploaded.toFixed(2)}
`); }, //#endregion //#region RenderTable loadTable(textFieldid, table, usingHeaders) { let idsToAppendFields = []; let htmlTable = ``; let currentFieldSection; let startingTableRow = 1; if (usingHeaders != false) { htmlTable += ` `; for (let i = 0; i < table[0].length; i++) { htmlTable += `` } htmlTable += ` `; } else { startingTableRow = 0; } for (let j = startingTableRow; j < table.length; j++) { htmlTable += ` `; for (let z = 0; z < table[j].length; z++) { if (z <= 0) { htmlTable += ``; } else { htmlTable += ``; idsToAppendFields.push({ fieldID: table[j][z], ID: `#${textFieldid}_${j}_${z}` }) } } htmlTable += ` `; } htmlTable += `
${table[0][i]}
${table[j][z]}
`; wizForms.getFieldsjQueryObjectsByFieldID(textFieldid).append(htmlTable); for (let w = 0; w < idsToAppendFields.length; w++) { let fieldSection = wizForms.getFieldsjQueryObjectsByFieldID(idsToAppendFields[w].fieldID); if (fieldSection != undefined) { fieldSection.parent().find("span").hide() currentFieldSection = fieldSection.parent().parent(); currentFieldSection.appendTo(idsToAppendFields[w].ID); } } }, //#endregion //#region FieldIDsTreeLogic loadFieldIDsTreeLogic(logic) { for (let i = 0; i < logic.length; i++) { wizForms.hideAllHideActionFields(logic[i]); wizForms.loadFieldIDsTreeLogicNodes(logic[i]); } }, loadFieldIDsTreeLogicNodes(logicNode) { let currentFieldID = Wiz(logicNode.fieldID); // if (logic.index != undefined) { // currentFieldID.on("change", function (currentFieldID) { // if (currentFieldID.getValue() == logic.triggerValue){ // triggerTreeNodeActions(actions) // } // }); // } // for (let i = 0; i < logic.actions.length; i++) { currentFieldID.on("change", function () { wizForms.triggerTreeNodeActions(currentFieldID, logicNode); }); // } }, triggerTreeNodeActions(currentFieldID, currentNode) { let actionState = true; let nodeDateObject; for (let i = 0; i < currentNode.actions.length; i++) { if (currentFieldID.type == "datePicker" && currentFieldID.getValue().length <= 0) { continue; } if (currentNode.actions[i].condition != undefined) { nodeDateObject = wizForms.StringHebrewDateConvertToDateObject(currentNode.actions[i].onValue); switch (currentNode.actions[i].condition) { case ">": if (currentFieldID.type == "datePicker") { if (currentFieldID.getDateObject() > nodeDateObject) { actionState = true; } else { actionState = false; } } else { if (currentFieldID.getValue() > currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; case "<": if (currentFieldID.type == "datePicker") { if (currentFieldID.getDateObject() < nodeDateObject) { actionState = true; } else { actionState = false; } } else { if (currentFieldID.getValue() < currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; case "<=": if (currentFieldID.type == "datePicker") { if (currentFieldID.getDateObject() <= nodeDateObject) { actionState = true; } else { actionState = false; } } else { if (currentFieldID.getValue() <= currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; case ">=": if (currentFieldID.type == "datePicker") { if (currentFieldID.getDateObject() >= nodeDateObject) { actionState = true; } else { actionState = false; } } else { if (currentFieldID.getValue() >= currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } break; } } else { if (currentFieldID.type != "checkBox") { if (currentFieldID.getValue() == currentNode.actions[i].onValue) { actionState = true; } else { actionState = false; } } else { if (currentFieldID.getValue().length > 0) { for (let g = 0; g < currentFieldID.getValue().length; g++) { if (currentFieldID.getValue()[g] != currentNode.actions[i].onValue) { actionState = false; } else { actionState = true; break; } } } else { actionState = false; } } } switch (currentNode.actions[i].actionType) { case "show": if (currentNode.actions[i].fieldIDs != undefined) { for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) { let currentActionFieldID = currentNode.actions[i].fieldIDs[j]; if (actionState != false) { Wiz(currentActionFieldID.fieldID).show(); } else { Wiz(currentActionFieldID.fieldID).setValue(""); Wiz(currentActionFieldID.fieldID).hide(); } if (currentActionFieldID.actions != undefined) { wizForms.loadFieldIDsTreeLogicNodes(currentActionFieldID); } } } break; case "hide": if (currentNode.actions[i].fieldIDs != undefined) { for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) { let currentActionFieldID = currentNode.actions[i].fieldIDs[j]; if (actionState != false) { Wiz(currentActionFieldID.fieldID).hide(); Wiz(currentActionFieldID.fieldID).setValue(""); } else { Wiz(currentActionFieldID.fieldID).show(); } if (currentActionFieldID.actions != undefined) { if (currentActionFieldID.actions.length > 0) { wizForms.loadFieldIDsTreeLogicNodes(currentActionFieldID); } } } } break; case "function": if (actionState != false) { let currentActionFieldID = currentNode.actions[i]; eval(currentActionFieldID.function); if (currentActionFieldID.actions != undefined) { if (currentActionFieldID.actions.length > 0) { wizForms.loadFieldIDsTreeLogic(currentActionFieldID); } } } break; } } }, hideAllHideActionFields(currentNode) { for (let i = 0; i < currentNode.actions.length; i++) { switch (currentNode.actions[i].actionType) { case "hide": for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) { let currentActionFieldID = currentNode.actions[i].fieldIDs[j]; Wiz(currentActionFieldID.fieldID).hide(); if (currentActionFieldID.actions != undefined) { if (currentActionFieldID.actions.length > 0) { wizForms.hideAllHideActionFields(currentActionFieldID); } } } break; case "show": for (let j = 0; j < currentNode.actions[i].fieldIDs.length; j++) { let currentActionFieldID = currentNode.actions[i].fieldIDs[j]; Wiz(currentActionFieldID.fieldID).hide(); if (currentActionFieldID.actions != undefined) { if (currentActionFieldID.actions.length > 0) { wizForms.hideAllHideActionFields(currentActionFieldID); } } } break; } } }, StringHebrewDateConvertToDateObject(inputDate) { const parts = inputDate.split('/'); if (parts.length === 3) { const swappedDate = `${parts[1]}/${parts[0]}/${parts[2]}`; return new Date(swappedDate); } else { return null; // Invalid input format } }, setCustomFooter(...logoLinks) { /* Creates a "פותח על ידי שחר" footer at the bottom of the form with custom links. The function can take any amount of links and will place them in the following fashion: From right to left and splitting the amount of logos in half on each side */ const upperView = $(".upperView") // Calculate the number of logo links const numLinks = logoLinks.length; // Calculate the number of links to be placed before and after the text const linksBeforeText = Math.floor(numLinks / 2); const beforeText = logoLinks.slice(0, linksBeforeText).map(link => ``).join(''); const afterText = logoLinks.slice(linksBeforeText).map(link => ``).join(''); const footer = `
${beforeText} פותח על ידי יחידת שחר ${afterText}
`; // Append the footer to the upperView upperView.append(footer); }, setFooter() { /* Sets default "פותח על ידי שחר" logo at the bottom of the form */ const upperView = $(".upperView") const footer = `
פותח על ידי יחידת שחר
` upperView.append(footer) }, setCustomHeader(position, ...logoLinks) { /* position (param) values: 1. center 2. flex-end 3. flex-start 4. space-around 5. space-between 6. space-evenly */ const validPositions = ["center", "flex-end", "flex-start", "space-around", "space-between", "space-evenly"]; const formHeader = $('.formHeader') const header = logoLinks.map(link => ``).join(''); formHeader.empty() formHeader.html(header) if (validPositions.includes(position)) { // Set the justify-content property based on the chosen position formHeader.css("justify-content", position); } else { // If an invalid position is provided, keep the default justify-content: center formHeader.css("justify-content", "center"); } }, setHeader() { const formHeader = $('.formHeader') const header = ` ` formHeader.empty() formHeader.html(header) }, loadNumericFields() { /* Dynamically adds a comma after every 3 digits in the input field. Must have class numeric for the function to work */ const numericFields = $('.numeric .textBox input'); numericFields.each(function () { $(this).on('input', setNumeric); }); function setNumeric() { /* Adds a comma after every 3 digits */ var inputValue = $(this).val(); // Remove any existing commas and non-digit characters var numericValue = inputValue.replace(/[^0-9]/g, ''); // Add commas after every 3 digits var formattedValue = numericValue.replace(/\B(?=(\d{3})+(?!\d))/g, ','); $(this).val(formattedValue); } }, loadPhoneNumberFields() { /* Adds a dash after the first 3 and first 6 digits of a phone number. Must have class 'phone' for the function to work */ const phoneFields = $('.phone .textBox input'); phoneFields.each(function () { $(this).on('input', setPhoneNumber); }); function setPhoneNumber() { var inputValue = $(this).val(); var numericValue = inputValue.replace(/[^0-9]/g, ''); var formattedValue = formatAsPhoneNumber(numericValue); $(this).val(formattedValue); } function formatAsPhoneNumber(value) { if (value.length > 6) { return value.replace(/(\d{3})(\d{3})(\d{1,4})/, '$1-$2-$3'); } else if (value.length > 3) { return value.replace(/(\d{3})(\d{1,3})/, '$1-$2'); } else { return value; } } }, loadNativeDateFields() { const dateFields = $('.date .textDate input') const dateTimeFields = $('.datetime .textDate input') dateFields.each(function () { replaceDate($(this), 'date'); }); dateTimeFields.each(function () { replaceDate($(this), 'datetime-local'); }); function replaceDate(elem, type) { // Create a new input element with updated properties var newInput = $('', { 'tabindex': elem.attr('tabindex'), 'type': type, 'use': elem.attr('use'), 'id': elem.attr('id'), 'mandatory': elem.attr('mandatory'), 'pdf': elem.attr('pdf'), 'validtype': elem.attr('validtype'), 'validationdata': elem.attr('validationdata'), 'aria-describedby': elem.attr('aria-describedby'), 'fieldid': elem.attr('fieldid'), 'mandatoryoriginalvalue': elem.attr('mandatoryoriginalvalue'), // Add any other attributes you need to copy }); // Replace the original input element with the new one elem.replaceWith(newInput); } }, setFieldClass() { /* Gives each wiz fields outter div a class and stops on fields with class spacing Example (Before calling the function):
(After calling the function):
*/ const allWizFields = $('[id^="elemID"]:not([id^="elemIDerr"])').toArray(); for (const field of allWizFields) { var id = $(field).attr('id') var type = getFieldType(id) // Assign type to div var div; if (type == "multiFileUpload") { div = $(field).parent().parent() } else { div = $(field).parent() } $(div).addClass(type); if (type == "checkbox") { $(field).css('display', ''); } } function getFieldType(id) { var field = $('#' + id) var children = field.children().toArray() var type = "noType" for (var child of children) { child = $(child) if (child.hasClass("headlineTitleBig") || child.hasClass("headlineTitle")) type = "title" else if (child.hasClass("textBox")) // Add option for השלמה אוטומטית type = "basic" else if (child.hasClass("textSelect")) type = "dropdown" else if (child.hasClass("textTitle")) type = "text" else if (child.hasClass("checkBoxtitle")) type = "checkbox" else if (child.hasClass("textRadio")) type = "radiobutton" else if (child.hasClass("mu_wrap_upload")) type = "multiFileUpload" else if (child.hasClass("fileUpload")) type = "uploadFile" else if (child.hasClass("textArea")) type = "textArea" else if (child.hasClass("dateSubTitle")) type = "date" else if (child.hasClass("timeSubTitle")) type = "time" else if (child.hasClass("signatureTextTitle")) type = "signature" } return type } }, /* function showDropDownValues(values, fieldid) { // Hides all dropdown options in values array [string] from being chosen const field = Wiz(fieldid) // const dropdownOptions = field.getOptions(); var dropdownOptions = $(`[fieldid="${fieldid}"] .textSelect select option`).toArray() // Shift is to keep "בחירה" option dropdownOptions.shift() for (const option of dropdownOptions) { if (!values.includes(option.text)){ $(option).css('display', 'none'); $(option).addClass("hidden"); } } } function showAllDropDownValues(fieldid) { // Shows all dropdown options (used to reset the options hidden after calling showAllDropDownValues() function) const field = Wiz(fieldid) // const dropdownOptions = field.getOptions(); var dropdownOptions = $(`[fieldid="${fieldid}"] .textSelect select option`).toArray() // Shift is to keep "בחירה" option dropdownOptions for (const option of dropdownOptions) { $(option).css('display', 'block') $(option).removeClass("hidden") } }*/ disable(fieldid) { Wiz(fieldid).jQueryFieldObject.find('select').attr('disabled', true); }, enable(fieldid) { Wiz(fieldid).jQueryFieldObject.find('select').attr('disabled', false); }, executeAfterHttpRequest (urlmatch, callback) { let send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function() { this.addEventListener('readystatechange', function() { if (this.responseURL.includes(urlmatch) && this.readyState === 4 && this.status === 200) { setTimeout(() => { callback(this); }); } }, false); send.apply(this, arguments); }; }, preFillResponseToJson(request) { return JSON.parse(JSON.parse(request.response).d) }, populateFields(fields) { if (!fields) return; Object.keys(fields).forEach(key => { const element = $(`[fieldid='${key}'] .textBox input`); if (element) { element.val(fields[key]); } }) }, } //#endregion class RootField { constructor(fieldid, children) { this.fieldid = fieldid; this.children = children; } } class Field extends RootField { constructor(fieldid, children, fatherValueToShow) { super(fieldid, children) } }