Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

add 'select-multiple' field

Forhad Hosain1948e390c7f9
diff --git a/packages/app/src/builder-ui/ui/form/createFormField.ts b/packages/app/src/builder-ui/ui/form/createFormField.ts
index d819e578..1e20367c 100644
--- a/packages/app/src/builder-ui/ui/form/createFormField.ts
+++ b/packages/app/src/builder-ui/ui/form/createFormField.ts
@@ -21,6 +21,7 @@ import {
createHint,
createInfoButton,
createInput,
+ createMultiSelectBox,
createRadio,
createRangeInput,
createSelectBox,
@@ -86,6 +87,42 @@ export default function createFormField(entry, displayType = 'block', entryIndex
isDropdown = true;
+ break;
+
+ case 'select-multiple':
+ case 'SELECT-MULTIPLE':
+ /**
+ * Native HTML multi-select field
+ * Supports multiple selections and search functionality
+ * Value should be an array of selected values
+ * createMultiSelectBox returns a container div with a nested select element
+ */
+ const multiSelectContainer = createMultiSelectBox(
+ entry.options,
+ Array.isArray(value) ? value : [],
+ entry?.dropdownHeight,
+ );
+
+ /**
+ * Get the actual select element from the container
+ * The container has a _selectElement property that references the select
+ */
+ const actualSelect = (multiSelectContainer as any)._selectElement as HTMLSelectElement;
+
+ if (entry.readonly && actualSelect) {
+ actualSelect.setAttribute('disabled', 'disabled');
+ }
+
+ /**
+ * Set formElement to the container, but store a reference to the select
+ * This allows the form system to work with the container while
+ * still being able to access the select for value retrieval
+ */
+ formElement = multiSelectContainer;
+ (formElement as any)._selectElement = actualSelect;
+
+ isDropdown = true;
+
break;
case 'checkbox':
case 'CHECKBOX':
@@ -425,16 +462,25 @@ export default function createFormField(entry, displayType = 'block', entryIndex
formElement.className += ` text-gray-900 border border-gray-200 sm:text-md ${fieldClasses}`;
if (entry?.type?.toLowerCase() !== 'key-value' && entry?.type?.toLowerCase() !== 'table') {
- formElement.setAttribute('id', entry.name);
- if (entry.name) formElement.setAttribute('name', entry.name);
+ /**
+ * For select-multiple, we need to apply id/name/attributes to the actual select element
+ * not the container div
+ */
+ const targetElement =
+ entry?.type?.toLowerCase() === 'select-multiple'
+ ? (formElement as any)._selectElement || formElement
+ : formElement;
+
+ targetElement.setAttribute('id', entry.name);
+ if (entry.name) targetElement.setAttribute('name', entry.name);
// We configure attributes for 'key-value' type fields separately in the '_createKvInputField()' function in the file 'src/frontend/ui/form/keyValueField.ts'.
for (let attr in attributes) {
if (attr === 'data-vault-exclusive' && [true, 'true'].includes(attributes[attr])) {
- formElement.setAttribute('disabled', 'disabled');
+ targetElement.setAttribute('disabled', 'disabled');
}
- formElement.setAttribute(attr, attributes[attr]);
+ targetElement.setAttribute(attr, attributes[attr]);
}
}
@@ -485,7 +531,13 @@ export default function createFormField(entry, displayType = 'block', entryIndex
formElement.setAttribute('data-deferred-events', JSON.stringify(events));
} else {
// Add events for non-tag inputs
- for (let event in events) formElement.addEventListener(event, events[event]);
+ // For select-multiple, attach events to the actual select element
+ const eventTarget =
+ entry?.type?.toLowerCase() === 'select-multiple'
+ ? (formElement as any)._selectElement || formElement
+ : formElement;
+
+ for (let event in events) eventTarget.addEventListener(event, events[event]);
}
// add template variables
@@ -526,8 +578,9 @@ export default function createFormField(entry, displayType = 'block', entryIndex
let labelElement = null;
if (label /*&& displayType !== 'inline'*/) {
labelElement = document.createElement('label');
- labelElement.className = `form-label text-[#1E1E1E] text-sm font-medium mb-1.5 ${attributes.labelCase ? attributes.labelCase : 'capitalize'
- }`;
+ labelElement.className = `form-label text-[#1E1E1E] text-sm font-medium mb-1.5 ${
+ attributes.labelCase ? attributes.labelCase : 'capitalize'
+ }`;
if (entry.type?.toLowerCase() === 'key-value' || entry.type?.toLowerCase() === 'table') {
labelElement.classList.add('form-label__kv');
diff --git a/packages/app/src/builder-ui/ui/form/fields.ts b/packages/app/src/builder-ui/ui/form/fields.ts
index d7970e8b..9d60cf42 100644
--- a/packages/app/src/builder-ui/ui/form/fields.ts
+++ b/packages/app/src/builder-ui/ui/form/fields.ts
@@ -1,5 +1,10 @@
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from '@src/react/shared/components/ui/tooltip';
import DOMPurify from 'dompurify';
-import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@src/react/shared/components/ui/tooltip';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { delay } from '../../utils';
@@ -240,6 +245,352 @@ export const createSelectBox = (
return select;
};
+/**
+ * Creates a simple, user-friendly multi-select with checkboxes and visual chips
+ * This uses native HTML5 elements without Metro UI
+ * Features:
+ * - Search input to filter options
+ * - Checkboxes for easy selection (simple click, no Ctrl/Cmd needed)
+ * - Visual chips showing selected items
+ * - Hidden select element for form compatibility
+ * @param options - Array of option objects with text and value properties
+ * @param value - Array of selected values
+ * @param dropdownHeight - Optional height for the options list in pixels
+ * @returns HTMLDivElement containing the complete multi-select UI
+ */
+export const createMultiSelectBox = (
+ options: Array<{ value: string; text: string }> | any,
+ value: string[],
+ dropdownHeight?: number,
+): HTMLDivElement => {
+ /**
+ * Main container - position relative for absolute positioning of dropdown
+ */
+ const container = document.createElement('div');
+ container.classList.add('multi-select-container');
+ container.style.cssText = 'display: flex; flex-direction: column; gap: 8px; position: relative;';
+
+ /**
+ * Selected items display area (chips/tags) with caret
+ */
+ const selectedChipsWrapper = document.createElement('div');
+ selectedChipsWrapper.style.cssText = 'position: relative; display: flex; align-items: center;';
+
+ const selectedChips = document.createElement('div');
+ selectedChips.classList.add('multi-select-chips');
+ selectedChips.style.cssText =
+ 'display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; padding: 6px 32px 6px 6px; border: 1px solid #d1d5db; border-radius: 6px; background: #f9fafb; flex: 1; cursor: pointer; transition: background-color 0.15s ease;';
+ selectedChips.innerHTML =
+ '<span style="color: #9ca3af; font-size: 14px;">No items selected</span>';
+
+ /**
+ * Add hover effect to chips area
+ */
+ selectedChips.addEventListener('mouseenter', () => {
+ selectedChips.style.backgroundColor = '#f3f4f6';
+ });
+ selectedChips.addEventListener('mouseleave', () => {
+ selectedChips.style.backgroundColor = '#f9fafb';
+ });
+
+ /**
+ * Caret/dropdown icon (inside selected chips area)
+ */
+ const caretIcon = document.createElement('span');
+ caretIcon.classList.add('multi-select-caret');
+ caretIcon.innerHTML = '▼';
+ caretIcon.style.cssText =
+ 'position: absolute; right: 10px; font-size: 12px; color: #6b7280; pointer-events: none; transition: transform 0.2s ease;';
+
+ /**
+ * Dropdown wrapper - contains search input and options list
+ * Positioned absolutely to float over other content
+ */
+ const dropdownWrapper = document.createElement('div');
+ dropdownWrapper.classList.add('multi-select-dropdown');
+ dropdownWrapper.style.cssText =
+ 'position: absolute; top: 100%; left: 0; right: 0; z-index: 1000; margin-top: 4px; display: none; flex-direction: column; gap: 8px; background: white; border: 1px solid #d1d5db; border-radius: 6px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); padding: 8px;';
+
+ /**
+ * Search input for filtering options
+ */
+ const searchInput = document.createElement('input');
+ searchInput.type = 'text';
+ searchInput.placeholder = 'Search options...';
+ searchInput.classList.add('multi-select-search', 'form-control');
+ searchInput.style.cssText =
+ 'padding: 8px; border-radius: 6px; border: 1px solid #d1d5db; width: 100%;';
+
+ /**
+ * Options list container with checkboxes
+ */
+ const optionsList = document.createElement('div');
+ optionsList.classList.add('multi-select-options');
+ const height = dropdownHeight || 200;
+ optionsList.style.cssText = `max-height: ${height}px; overflow-y: auto; border-radius: 6px; background: white;`;
+
+ /**
+ * Hidden select element for form compatibility
+ * This stores the actual selected values for form submission
+ */
+ const hiddenSelect = document.createElement('select');
+ hiddenSelect.setAttribute('multiple', 'multiple');
+ hiddenSelect.style.display = 'none';
+ hiddenSelect.classList.add('multi-select-native');
+
+ /**
+ * Store all options and selected values
+ */
+ let allOptions: Array<{ value: string; text: string }> = [];
+ const selectedValues = new Set<string>(Array.isArray(value) ? value : []);
+
+ /**
+ * Create a chip element for a selected item
+ */
+ const createChip = (optionValue: string, optionText: string): HTMLElement => {
+ const chip = document.createElement('span');
+ chip.style.cssText =
+ 'display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; background: #3b82f6; color: white; border-radius: 4px; font-size: 14px;';
+ chip.innerHTML = `
+ ${optionText}
+ <button type="button" style="background: none; border: none; color: white; cursor: pointer; font-size: 16px; line-height: 1; padding: 0; margin-left: 4px;" data-value="${optionValue}">&times;</button>
+ `;
+
+ // Remove chip on click
+ const removeBtn = chip.querySelector('button') as HTMLButtonElement;
+ removeBtn.addEventListener('click', (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ const val = removeBtn.getAttribute('data-value');
+ if (val) {
+ selectedValues.delete(val);
+ updateUI();
+ // Trigger change event
+ hiddenSelect.dispatchEvent(new Event('change', { bubbles: true }));
+ }
+ });
+
+ return chip;
+ };
+
+ /**
+ * Update the UI based on selected values
+ */
+ const updateUI = (): void => {
+ // Update chips display
+ selectedChips.innerHTML = '';
+ if (selectedValues.size === 0) {
+ selectedChips.innerHTML =
+ '<span style="color: #9ca3af; font-size: 14px;">No items selected</span>';
+ } else {
+ selectedValues.forEach((val) => {
+ const option = allOptions.find((opt) => opt.value === val);
+ if (option) {
+ selectedChips.appendChild(createChip(option.value, option.text));
+ }
+ });
+ }
+
+ // Update hidden select
+ hiddenSelect.innerHTML = '';
+ selectedValues.forEach((val) => {
+ const option = document.createElement('option');
+ option.value = val;
+ option.selected = true;
+ hiddenSelect.appendChild(option);
+ });
+
+ // Update checkmark icons in the options list
+ const optionItems = optionsList.querySelectorAll('[data-value]');
+ optionItems.forEach((item) => {
+ const value = item.getAttribute('data-value');
+ const checkmark = item.querySelector('.checkmark-icon') as HTMLElement;
+ if (checkmark && value) {
+ checkmark.style.display = selectedValues.has(value) ? 'inline-block' : 'none';
+ }
+ });
+ };
+
+ /**
+ * Create option element with checkmark icon
+ */
+ const createOptionElement = (option: { value: string; text: string }): HTMLElement => {
+ const isSelected = selectedValues.has(option.value);
+
+ const label = document.createElement('div');
+ label.style.cssText =
+ 'display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; cursor: pointer; user-select: none; border-bottom: 1px solid #f3f4f6;';
+ label.setAttribute('data-value', option.value);
+
+ label.innerHTML = `
+ <span style="font-size: 14px;">${option.text}</span>
+ <span class="checkmark-icon" style="font-size: 18px; color: #10b981; font-weight: bold; display: ${isSelected ? 'inline-block' : 'none'};">✓</span>
+ `;
+
+ // Handle click to toggle selection
+ label.addEventListener('click', () => {
+ const value = label.getAttribute('data-value');
+ if (!value) return;
+
+ const checkmark = label.querySelector('.checkmark-icon') as HTMLElement;
+
+ if (selectedValues.has(value)) {
+ selectedValues.delete(value);
+ checkmark.style.display = 'none';
+ } else {
+ selectedValues.add(value);
+ checkmark.style.display = 'inline-block';
+ }
+
+ updateUI();
+ // Trigger change event on hidden select
+ hiddenSelect.dispatchEvent(new Event('change', { bubbles: true }));
+ });
+
+ // Hover effect
+ label.addEventListener('mouseenter', () => {
+ label.style.background = '#f3f4f6';
+ });
+ label.addEventListener('mouseleave', () => {
+ label.style.background = 'white';
+ });
+
+ return label;
+ };
+
+ /**
+ * Populate options list with optional filtering
+ */
+ const populateOptions = (filterText: string = ''): void => {
+ optionsList.innerHTML = '';
+
+ const filtered = filterText
+ ? allOptions.filter(
+ (option) =>
+ option.text.toLowerCase().includes(filterText.toLowerCase()) ||
+ option.value.toLowerCase().includes(filterText.toLowerCase()),
+ )
+ : allOptions;
+
+ if (filtered.length === 0) {
+ optionsList.innerHTML =
+ '<div style="padding: 12px; text-align: center; color: #9ca3af;">No options found</div>';
+ } else {
+ filtered.forEach((option) => {
+ optionsList.appendChild(createOptionElement(option));
+ });
+ }
+ };
+
+ /**
+ * Toggle dropdown visibility
+ */
+ let isOpen = false;
+ const toggleDropdown = (): void => {
+ isOpen = !isOpen;
+ dropdownWrapper.style.display = isOpen ? 'flex' : 'none';
+ caretIcon.style.transform = isOpen ? 'rotate(180deg)' : 'rotate(0deg)';
+
+ // Focus search input when opening
+ if (isOpen) {
+ setTimeout(() => searchInput.focus(), 100);
+ } else {
+ searchInput.value = '';
+ populateOptions('');
+ }
+ };
+
+ /**
+ * Set up selected chips click handler to toggle dropdown
+ */
+ selectedChips.addEventListener('click', (e) => {
+ // Don't toggle if clicking on remove button
+ const target = e.target as HTMLElement;
+ if (target.tagName === 'BUTTON' || target.closest('button')) {
+ return;
+ }
+ e.stopPropagation();
+ toggleDropdown();
+ });
+
+ /**
+ * Set up search input for filtering
+ */
+ searchInput.addEventListener('input', (e) => {
+ const target = e.target as HTMLInputElement;
+ populateOptions(target.value);
+ });
+
+ /**
+ * Prevent closing when clicking on search input
+ */
+ searchInput.addEventListener('click', (e) => {
+ e.stopPropagation();
+ });
+
+ /**
+ * Close dropdown when clicking outside
+ */
+ document.addEventListener('click', (e) => {
+ if (!container.contains(e.target as Node) && isOpen) {
+ toggleDropdown();
+ }
+ });
+
+ /**
+ * Handle async or sync options
+ */
+ if (typeof options === 'function') {
+ setTimeout(() => {
+ const formBox = container.closest('.form-box');
+ if (formBox) formBox.classList.add('loading');
+ }, 300);
+
+ options().then((data: Array<{ value: string; text: string }>) => {
+ allOptions = data;
+ populateOptions();
+ updateUI();
+
+ const formBox = container.closest('.form-box');
+ if (formBox) {
+ setTimeout(() => {
+ formBox.classList.remove('loading');
+ }, 300);
+ }
+ });
+ } else {
+ allOptions = options;
+ populateOptions();
+ updateUI();
+ }
+
+ /**
+ * Assemble the selected chips wrapper
+ */
+ selectedChipsWrapper.appendChild(selectedChips);
+ selectedChipsWrapper.appendChild(caretIcon);
+
+ /**
+ * Assemble the dropdown wrapper (floating)
+ */
+ dropdownWrapper.appendChild(searchInput);
+ dropdownWrapper.appendChild(optionsList);
+
+ /**
+ * Assemble the container
+ */
+ container.appendChild(selectedChipsWrapper);
+ container.appendChild(dropdownWrapper);
+ container.appendChild(hiddenSelect);
+
+ /**
+ * Store reference to the hidden select element for form handling
+ */
+ (container as any)._selectElement = hiddenSelect;
+
+ return container;
+};
+
export const createCheckbox = (label: string, value: string): HTMLInputElement => {
const checkbox = document.createElement('input');
checkbox.setAttribute('data-role', 'checkbox');
@@ -554,9 +905,7 @@ function getCodeConfigFromAttributes(
/**
* Get code configuration based on content type (APICall components)
*/
-function getCodeConfigFromContentType(
- textarea: HTMLTextAreaElement,
-): CodeConfig | undefined {
+function getCodeConfigFromContentType(textarea: HTMLTextAreaElement): CodeConfig | undefined {
const contentType = textarea.getAttribute('data-content-type');
if (!contentType) return undefined;
@@ -723,7 +1072,9 @@ async function initializeCodeEditor(
}
// Setup bracket selection for Ace editor content
- const aceContentElement = textarea._editor.container?.querySelector('.ace_content') as HTMLElement | null;
+ const aceContentElement = textarea._editor.container?.querySelector(
+ '.ace_content',
+ ) as HTMLElement | null;
if (aceContentElement) {
addBracketSelection(aceContentElement);
}
@@ -882,7 +1233,9 @@ function setupVaultInDialog(
if (targetField) {
(targetField as HTMLTextAreaElement).focus();
- (targetField as HTMLTextAreaElement).scrollTop = (targetField as HTMLTextAreaElement).scrollHeight;
+ (targetField as HTMLTextAreaElement).scrollTop = (
+ targetField as HTMLTextAreaElement
+ ).scrollHeight;
const inputEvent = new Event('input', { bubbles: true });
(targetField as HTMLTextAreaElement).dispatchEvent(inputEvent);
@@ -895,9 +1248,9 @@ function setupVaultInDialog(
// After vault handler runs, ensure focus/update
setTimeout(() => {
- const updatedTargetField = (newVaultButton.closest('.form-group')?.querySelector(
- '[data-vault]'
- ) as HTMLTextAreaElement | null);
+ const updatedTargetField = newVaultButton
+ .closest('.form-group')
+ ?.querySelector('[data-vault]') as HTMLTextAreaElement | null;
if (updatedTargetField) {
updatedTargetField.focus();
updatedTargetField.scrollTop = updatedTargetField.scrollHeight;
@@ -938,7 +1291,8 @@ function reattachActionButtons(
) as HTMLButtonElement | null;
if (!modalActionButton) return;
- const originalClickHandler = (originalButton as unknown as { onclick?: (e: Event) => void }).onclick;
+ const originalClickHandler = (originalButton as unknown as { onclick?: (e: Event) => void })
+ .onclick;
if (originalClickHandler) {
modalActionButton.onclick = async (event) => {
const buttonId = originalButton.id;
@@ -962,7 +1316,8 @@ function reattachActionButtons(
};
}
- const originalEvents = (originalButton as unknown as { _events?: Record<string, EventListener> })._events || {};
+ const originalEvents =
+ (originalButton as unknown as { _events?: Record<string, EventListener> })._events || {};
Object.keys(originalEvents).forEach((eventType) => {
modalActionButton.addEventListener(eventType, originalEvents[eventType] as EventListener);
});
@@ -1020,7 +1375,6 @@ async function handleExpandTextarea(
modalTextarea.classList.add('form-control', 'flex-1', 'resize-none', 'overflow-y-auto');
modalTextarea.id = 'expanded-textarea';
-
// Copy validation attributes from original textarea for Metro UI validation
const validateAttr = originalTextarea.getAttribute('data-validate');
if (validateAttr) {
diff --git a/packages/app/src/builder-ui/ui/form/form.ts b/packages/app/src/builder-ui/ui/form/form.ts
index 07be02d3..a27b0475 100644
--- a/packages/app/src/builder-ui/ui/form/form.ts
+++ b/packages/app/src/builder-ui/ui/form/form.ts
@@ -277,6 +277,16 @@ export function readFormValues(form, entriesObject) {
.filter((checkbox) => checkbox.checked)
.map((checkbox) => checkbox.value);
break;
+ case 'select-multiple':
+ case 'SELECT-MULTIPLE':
+ /**
+ * For select-multiple, get all selected option values as an array
+ * The inputField is the hidden select element with multiple attribute
+ */
+ result[key] = Array.from(inputField.selectedOptions).map(
+ (option: HTMLOptionElement) => option.value,
+ );
+ break;
case 'toggle':
result[key] = inputField.checked;
break;
@@ -350,6 +360,17 @@ export function readFormValidation(form, entriesObject) {
case 'toggle':
result[key] = { value: inputField.checked };
break;
+ case 'select-multiple':
+ case 'SELECT-MULTIPLE':
+ /**
+ * For select-multiple validation, return array of selected values
+ */
+ result[key] = {
+ value: Array.from(inputField.selectedOptions).map(
+ (option: HTMLOptionElement) => option.value,
+ ),
+ };
+ break;
case 'number':
// Convert string value to number for number fields
const numberValue = inputField.value;