diff --git a/src/controls/editor/editform.js b/src/controls/editor/editform.js index c50f8d64a..191411bc6 100644 --- a/src/controls/editor/editform.js +++ b/src/controls/editor/editform.js @@ -1,4 +1,23 @@ +/** + * Generates a form element dynamically based on the provided configuration object. + * @param {Object} obj - The configuration object for creating the form element. + * @param {string} obj.elId - The ID of the HTML element. + * @param {string} obj.cls - Additional CSS classes. + * @param {boolean} obj.isVisible - Determines if the element is visible. + * @param {string} obj.title - The label for the form element. + * @param {*} obj.val - The value of the element. + * @param {string} obj.type - The type of the form element (e.g., 'text', 'checkbox'). + * @param {number} [obj.maxLength] - Maximum length for input fields. + * @param {Array} [obj.options] - Options for dropdowns or checkboxes. + * @param {boolean} [obj.readonly] - Whether the field is readonly. + * @param {boolean} [obj.required] - Whether the field is required. + * @param {string} [obj.name] - The name attribute for the element. + * @param {string} [obj.defaultDate] - Default value for date fields. + * @param {string} [obj.defaultColor] - Default color value for color fields. + * @returns {string} The HTML string for the form element. + */ const createForm = function createForm(obj) { + // Basic setup of variables const id = obj.elId; let cls = obj.cls || ''; cls += id; @@ -26,18 +45,24 @@ const createForm = function createForm(obj) { let firstOption; let checked; const maxLengthText = maxLength ? `, max ${obj.maxLength} tecken` : ''; + + // Switch statement to handle different field types switch (type) { case 'text': + // Create a text input el = `
`; break; case 'textarea': + // Create a textarea el = `
`; break; case 'checkbox': + // Create a checkbox checked = (obj.config && obj.config.uncheckedValue ? obj.config.uncheckedValue !== val : val) ? ' checked' : ''; el = `
`; break; case 'checkboxgroup': + // Create a group of checkboxes el = `

`; options.forEach((opt, index) => { const option = opt.text; @@ -65,6 +90,7 @@ const createForm = function createForm(obj) { el += '
'; break; case 'dropdown': + // Create a dropdown if (val) { firstOption = ``; } else { @@ -77,6 +103,7 @@ const createForm = function createForm(obj) { el += ''; break; case 'searchList': + // Create a searchList input elLabel.innerHTML = label; elLabel.appendChild(document.createElement('br')); @@ -105,6 +132,7 @@ const createForm = function createForm(obj) { el = elDiv.outerHTML; break; case 'image': { + // Create a image input const imageClass = val ? '' : 'o-hidden'; el = `