Skip to content

Beautiful Open-Source Form Builder

Enhance form components with new icon and field state features

Julien Nahum2143d1e4242f
diff --git a/client/components/forms/core/components/InputLabel.vue b/client/components/forms/core/components/InputLabel.vue
index 05c5d722d..1f82b0168 100644
--- a/client/components/forms/core/components/InputLabel.vue
+++ b/client/components/forms/core/components/InputLabel.vue
@@ -4,11 +4,14 @@
:class="ui.label()"
>
<slot>
- {{ label }}
+ <span class="align-baseline">{{ label }}</span>
<span
v-if="required"
:class="ui.requiredDot()"
- >*</span>
+ aria-hidden="true"
+ >
+ <Icon name="i-ix-mandatory" />
+ </span>
</slot>
</label>
</template>
diff --git a/client/components/open/forms/BlockRenderer.vue b/client/components/open/forms/BlockRenderer.vue
index 09573feae..aa5a6bafa 100644
--- a/client/components/open/forms/BlockRenderer.vue
+++ b/client/components/open/forms/BlockRenderer.vue
@@ -59,6 +59,9 @@ const dataForm = computed(() => props.formManager?.form || {})
const darkMode = computed(() => props.formManager?.darkMode?.value || false)
const strategy = computed(() => props.formManager?.strategy?.value || {})
+// Use centralized fieldState from manager
+const fieldState = computed(() => props.formManager?.fieldState)
+
const { getFormComponent } = useComponentRegistry()
const componentInfo = computed(() => {
@@ -133,11 +136,13 @@ const shouldInjectBetweenMedia = computed(() => (
const boundProps = computed(() => {
const field = props.block
if (!field) return {}
+ const unified = fieldState.value?.getState(field) || { required: !!field?.required, effectiveDisabled: !!field?.disabled, hiddenIndicator: !!field?.hidden }
+
const inputProperties = {
key: field.id,
name: field.id,
form: dataForm.value,
- label: (field.hide_field_name) ? null : field.name + ((field.hidden) ? ' (Hidden Field)' : ''),
+ label: (field.hide_field_name) ? null : field.name + (unified.hiddenIndicator ? ' (Hidden Field)' : ''),
color: form.value.color,
placeholder: field.placeholder,
help: field.help,
@@ -149,9 +154,8 @@ const boundProps = computed(() => {
locale: (form.value?.language) ? form.value.language : 'en',
media: shouldInjectBetweenMedia.value ? field.image : null,
presentation: form.value?.presentation_style || 'classic',
- required: field.required || false,
- // Respect global disable flag from form mode (e.g., READ_ONLY)
- disabled: (strategy.value?.display?.disableFields === true) || (field.disabled || false)
+ required: !!unified.required,
+ disabled: !!unified.effectiveDisabled
}
if (field.type === 'matrix') {
diff --git a/client/components/open/forms/fields/FormFieldEdit.vue b/client/components/open/forms/fields/FormFieldEdit.vue
index 06a3c22c1..0d04fb2c1 100644
--- a/client/components/open/forms/fields/FormFieldEdit.vue
+++ b/client/components/open/forms/fields/FormFieldEdit.vue
@@ -244,6 +244,7 @@ const dropdownItems = computed(() => {
label: 'Remove',
icon: 'i-heroicons-trash-20-solid',
color: 'error',
+ kbds: ['meta', 'backspace'],
onClick: removeBlock
}])
diff --git a/client/lib/forms/composables/useFieldState.js b/client/lib/forms/composables/useFieldState.js
new file mode 100644
index 000000000..db0fe5a94
--- /dev/null
+++ b/client/lib/forms/composables/useFieldState.js
@@ -0,0 +1,73 @@
+import { computed, toValue } from 'vue'
+import FormLogicPropertyResolver from '~/lib/forms/FormLogicPropertyResolver.js'
+
+/**
+ * Centralized field state resolver for a form instance.
+ * Required inputs: formDataRef, formRef (with properties), strategyRef.
+ * Provides a big computed map to minimize recomputation and a getState(field) accessor.
+ *
+ * Unified state shape:
+ * { hidden, required, disabled, effectiveDisabled, hiddenIndicator }
+ */
+export function useFieldState(formDataRef, formRef, strategyRef) {
+ function resolveRawState(field) {
+ try {
+ const currentData = toValue(formDataRef) || {}
+ const resolver = new FormLogicPropertyResolver(field, currentData)
+ return {
+ hidden: !!resolver.isHidden(),
+ required: !!resolver.isRequired(),
+ disabled: !!resolver.isDisabled()
+ }
+ } catch {
+ return {
+ hidden: !!field?.hidden,
+ required: !!field?.required,
+ disabled: !!field?.disabled
+ }
+ }
+ }
+
+ function withDerived(raw, strategy) {
+ const effectiveDisabled = strategy?.display?.disableFields === true
+ ? true
+ : (strategy?.display?.enableDisabledFields === true ? false : !!raw.disabled)
+ const hiddenIndicator = !!(strategy?.display?.showHiddenFields === true && raw.hidden)
+ return {
+ hidden: raw.hidden,
+ required: raw.required,
+ disabled: raw.disabled,
+ effectiveDisabled,
+ hiddenIndicator
+ }
+ }
+
+ // Big computed map keyed by field.id over formRef.properties
+ const statesById = computed(() => {
+ const form = toValue(formRef) || {}
+ const strategy = toValue(strategyRef) || {}
+ const properties = form?.properties || []
+ const map = new Map()
+ for (const field of properties) {
+ if (!field || !field.id) continue
+ const raw = resolveRawState(field)
+ map.set(field.id, withDerived(raw, strategy))
+ }
+ return map
+ })
+
+ /**
+ * Get the unified state for a given field; prefers precomputed map entry.
+ */
+ function getState(field) {
+ const strategy = toValue(strategyRef) || {}
+ if (field?.id && statesById.value.has(field.id)) return statesById.value.get(field.id)
+ const raw = resolveRawState(field)
+ return withDerived(raw, strategy)
+ }
+
+ return {
+ getState,
+ statesById
+ }
+}
diff --git a/client/lib/forms/composables/useFocusedStructure.js b/client/lib/forms/composables/useFocusedStructure.js
index ba70c54dc..ac9373207 100644
--- a/client/lib/forms/composables/useFocusedStructure.js
+++ b/client/lib/forms/composables/useFocusedStructure.js
@@ -1,12 +1,21 @@
import { computed, toValue } from 'vue'
-export function useFocusedStructure(formConfig, managerState, _formData) {
+export function useFocusedStructure(formConfig, managerState, formData, fieldState) {
const form = computed(() => toValue(formConfig) || { properties: [] })
- const fieldGroups = computed(() => {
+ const isHidden = (field) => {
+ try { return !!fieldState.getState(field).hidden } catch { return !!field?.hidden }
+ }
+
+ const visibleProperties = computed(() => {
const properties = form.value.properties || []
+ // Focused: one field per page; exclude hidden fields so slides are never empty
+ return properties.filter(field => !isHidden(field))
+ })
+
+ const fieldGroups = computed(() => {
+ const properties = visibleProperties.value || []
if (properties.length === 0) return [[]]
- // One field per page
return properties.map(field => [field])
})
@@ -48,7 +57,7 @@ export function useFocusedStructure(formConfig, managerState, _formData) {
// Utilities used by editor/drag in classic; provide no-ops or simple mapping
const getPageForField = (fieldIndex) => {
- const properties = form.value.properties || []
+ const properties = visibleProperties.value || []
if (properties.length === 0) return 0
if (fieldIndex < 0 || fieldIndex >= properties.length) return 0
return fieldIndex
@@ -64,13 +73,14 @@ export function useFocusedStructure(formConfig, managerState, _formData) {
const getTargetDropIndex = (relativeDropIndex, targetPageIndex) => {
// In focused mode each page has exactly one field; drop index maps directly
- return Math.max(0, Math.min(targetPageIndex, (form.value.properties || []).length))
+ const properties = visibleProperties.value || []
+ return Math.max(0, Math.min(targetPageIndex, properties.length))
}
const determineInsertIndex = (selectedFieldIndex, currentPageIndex, explicitIndex = null, _insertOnSamePage = false) => {
if (explicitIndex !== null && typeof explicitIndex === 'number') return explicitIndex
if (selectedFieldIndex !== null && selectedFieldIndex !== undefined && selectedFieldIndex >= 0) return selectedFieldIndex + 1
- const properties = form.value.properties || []
+ const properties = visibleProperties.value || []
if (properties.length === 0) return 0
const pageIdx = currentPageIndex ?? managerState?.currentPage ?? 0
return Math.max(0, Math.min(properties.length, pageIdx + 1))
diff --git a/client/lib/forms/composables/useFormManager.js b/client/lib/forms/composables/useFormManager.js
index dabd0e357..d3e0b56a4 100644
--- a/client/lib/forms/composables/useFormManager.js
+++ b/client/lib/forms/composables/useFormManager.js
@@ -14,6 +14,7 @@ import { useIsIframe } from '~/composables/useIsIframe'
import { useAmplitude } from '~/composables/useAmplitude'
import { useConfetti } from '~/composables/useConfetti'
import { cloneDeep } from 'lodash'
+import { useFieldState } from './useFieldState'
/**
* @fileoverview Main orchestrator composable for form operations.
@@ -47,6 +48,9 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
// Create a reactive reference to the form data for dependent composables to watch
const formDataRef = computed(() => form.data())
+ // Centralized field state (single instance per manager)
+ const fieldState = useFieldState(formDataRef, computed(() => config.value), computed(() => strategy.value))
+
// Instantiate pending submission service (handles localStorage saving)
const pendingSubmissionService = usePendingSubmission(config, formDataRef)
@@ -63,8 +67,8 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
const forceClassic = !!strategy.value?.display?.forceClassicPresentation
const style = forceClassic ? 'classic' : ((toValue(config)?.presentation_style) || 'classic')
return style === 'focused'
- ? useFocusedStructure(config, state, form)
- : useFormStructure(config, state, form)
+ ? useFocusedStructure(config, state, form, fieldState)
+ : useFormStructure(config, state, form, fieldState)
}
function replaceStructure() {
@@ -329,7 +333,7 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
throw error
}
}
-
+
/** Resets the form to its initial state for refilling. */
const restart = async () => {
state.isSubmitted = false
@@ -374,6 +378,7 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
// Composables (Expose if direct access needed, often not necessary)
structure,
+ fieldState, // Expose centralized field state service
payment, // Expose payment service
// Core Methods
diff --git a/client/lib/forms/composables/useFormStructure.js b/client/lib/forms/composables/useFormStructure.js
index 8617d0b97..5c7787021 100644
--- a/client/lib/forms/composables/useFormStructure.js
+++ b/client/lib/forms/composables/useFormStructure.js
@@ -1,24 +1,18 @@
import { computed, toValue } from 'vue'
-import FormLogicPropertyResolver from '~/lib/forms/FormLogicPropertyResolver.js'
/**
* @fileoverview Composable responsible for analyzing and managing the structural aspects of a form,
* including page breaks, field grouping, page boundaries, and determining field locations.
*/
-export function useFormStructure(formConfig, managerState, formData) {
+export function useFormStructure(formConfig, managerState, formData, fieldState) {
const form = computed(() => toValue(formConfig) || { properties: [] })
/**
- * Checks if a field is hidden based on form logic.
- * Uses FormLogicPropertyResolver.
- * @param {Object} field - The field configuration object.
- * @returns {Boolean} True if the field is hidden, false otherwise.
+ * Checks if a field is hidden based on centralized field state service.
*/
const isFieldHidden = (field) => {
try {
- // Use the formData ref passed into the composable
- const currentFormData = toValue(formData) || {}
- return new FormLogicPropertyResolver(field, currentFormData).isHidden()
+ return !!fieldState.getState(field).hidden
} catch (e) {
console.error("Error checking if field is hidden:", field?.id, e)
return field?.hidden || false // Fallback
@@ -27,6 +21,7 @@ export function useFormStructure(formConfig, managerState, formData) {
/**
* Calculates the groups of fields based on non-hidden page breaks.
+ * Classic mode: split on visible page breaks and ignore empty pages (groups containing only page-breaks).
* @returns {Array<Array<Object>>} Nested array where each inner array represents a page.
*/
const calculateFieldGroups = () => {
@@ -35,24 +30,29 @@ export function useFormStructure(formConfig, managerState, formData) {
const groups = []
let currentGroup = []
+ let hasRenderable = false // any non-page-break field in this group
+
+ const pushGroupIfRenderable = () => {
+ if (currentGroup.length === 0) return
+ if (hasRenderable) groups.push([...currentGroup])
+ currentGroup = []
+ hasRenderable = false
+ }
properties.forEach((field, index) => {
currentGroup.push(field)
+ if (field.type !== 'nf-page-break') hasRenderable = true
- // Check if the field is a page break AND it's not hidden
+ // Split only on non-hidden page breaks
if (field.type === 'nf-page-break' && !isFieldHidden(field)) {
- groups.push([...currentGroup])
- if (index < properties.length - 1) {
- currentGroup = []
- }
+ pushGroupIfRenderable()
}
- })
- // Add the last group if it's not empty AND the last field wasn't a non-hidden page break
- const lastProperty = properties[properties.length - 1]
- if (currentGroup.length > 0 && (!lastProperty || lastProperty.type !== 'nf-page-break' || isFieldHidden(lastProperty))) {
- groups.push(currentGroup)
- }
+ // Last item safety
+ if (index === properties.length - 1) {
+ pushGroupIfRenderable()
+ }
+ })
// Ensure at least one group exists
if (groups.length === 0) {
@@ -368,7 +368,7 @@ export function useFormStructure(formConfig, managerState, formData) {
getPageForField, // Find which page a field index belongs to
hasPaymentBlock, // Check if a page has a payment block
getPaymentBlock, // Get the payment block from a page
- isFieldHidden, // Check if a specific field is hidden by logic
+ isFieldHidden, // Check if a specific field is hidden by state
getTargetDropIndex, // Calculate absolute index for drag/drop
determineInsertIndex, // Calculate where to insert a new field
setPageForField // Set the current page to the page containing the specified field
diff --git a/client/lib/forms/themes/input-label.theme.js b/client/lib/forms/themes/input-label.theme.js
index 2b11751fb..0ac41c7f2 100644
--- a/client/lib/forms/themes/input-label.theme.js
+++ b/client/lib/forms/themes/input-label.theme.js
@@ -5,10 +5,10 @@
export const inputLabelTheme = {
slots: {
label: [
- 'input-label',
+ 'input-label inline align-baseline',
'text-neutral-700 dark:text-neutral-300'
],
- requiredDot: 'text-red-500 required-dot'
+ requiredDot: 'text-red-500 rounded-full bg-red-100 required-dot inline-flex items-center align-middle ml-1 *:size-4 *:-m-0.5'
},
variants: {
presentation: {
@@ -36,13 +36,15 @@ export const inputLabelTheme = {
label: 'text-xs'
},
sm: {
- label: 'text-xs'
+ label: 'text-xs',
},
md: {
- label: 'text-sm'
+ label: 'text-sm',
+ requiredDot: 'mt-[-1px]!'
},
lg: {
- label: 'text-base'
+ label: 'text-base',
+ requiredDot: '*:size-5 mt-[-3px]!'
}
},
uppercaseLabels: {
diff --git a/client/package-lock.json b/client/package-lock.json
index e279393cf..8c7e03727 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -65,6 +65,7 @@
"@iconify-json/clarity": "^1.2.1",
"@iconify-json/heroicons": "^1.2.2",
"@iconify-json/ic": "^1.2.1",
+ "@iconify-json/ix": "^1.2.10",
"@iconify-json/octicon": "^1.2.1",
"@iconify-json/tabler": "^1.2.1",
"@nuxt/eslint-config": "^1.3.0",
@@ -1679,6 +1680,16 @@
"@iconify/types": "*"
}
},
+ "node_modules/@iconify-json/ix": {
+ "version": "1.2.10",
+ "resolved": "https://registry.npmjs.org/@iconify-json/ix/-/ix-1.2.10.tgz",
+ "integrity": "sha512-2NMqsW+sMyH+cpRnRW6mVqJM/q3Mbb7UVY9NWJJEJfHGn1SbzZde/jpgEmTZe5jMJMPQGWhaCzbGsTMrFim+3Q==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@iconify/types": "*"
+ }
+ },
"node_modules/@iconify-json/material-symbols": {
"version": "1.2.29",
"resolved": "https://registry.npmjs.org/@iconify-json/material-symbols/-/material-symbols-1.2.29.tgz",
diff --git a/client/package.json b/client/package.json
index fb18a5766..2bdbc4629 100644
--- a/client/package.json
+++ b/client/package.json
@@ -16,6 +16,7 @@
"@iconify-json/clarity": "^1.2.1",
"@iconify-json/heroicons": "^1.2.2",
"@iconify-json/ic": "^1.2.1",
+ "@iconify-json/ix": "^1.2.10",
"@iconify-json/octicon": "^1.2.1",
"@iconify-json/tabler": "^1.2.1",
"@nuxt/eslint-config": "^1.3.0",