corrad-bp/composables/safeGetField.js
Afiq 3abaf7afe5 Enhance Form Builder with Repeating Group Functionality and Data Management
- Added support for initializing and managing repeating groups in ComponentPreview.vue, allowing for dynamic creation of group items based on minimum item settings.
- Implemented event emission for form data updates to notify parent components, ensuring synchronization with FormKit integration.
- Enhanced FormBuilderFieldSettingsModal.vue with new configuration options for repeating tables, including minimum and maximum records, button text settings, and table behavior controls.
- Updated safeGetField.js to ensure backward compatibility by returning empty strings for undefined or null values.
- Improved workflow page to handle form data updates from ComponentPreview, maintaining data consistency across the application.
- Enhanced form store logic to initialize preview form data for repeating groups upon component addition and form loading.
2025-08-06 15:12:52 +08:00

16 lines
568 B
JavaScript

// Utility to safely get a field value from a form data object
export function safeGetField(field, formData) {
if (formData && Object.prototype.hasOwnProperty.call(formData, field)) {
const value = formData[field];
// If the value is undefined or null, return empty string for backward compatibility
if (value === undefined || value === null) {
return '';
}
return value;
}
if (process.env.NODE_ENV !== 'production') {
// Only warn in development
console.warn(`Field '${field}' is missing or inaccessible.`);
}
return '';
}