- Updated ComponentPreview.vue to improve the handling of repeating groups, including the addition of helper functions for field value retrieval and input handling. - Enhanced the rendering of repeating groups with better structure and improved user experience, including dynamic item addition and removal. - Modified RepeatingTable.vue to increase the maximum visible columns from 20 to 50, allowing for better data presentation and horizontal scrolling. - Improved column width calculations and added a minimum table width to ensure proper layout and usability. - Updated safeGetField.js to allow for optional warning suppression, enhancing flexibility in data access without unnecessary console warnings. - Refined styles across components for better visual consistency and usability.
21 lines
839 B
JavaScript
21 lines
839 B
JavaScript
// Utility to safely get a field value from a form data object
|
|
export function safeGetField(field, formData, options = {}) {
|
|
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;
|
|
}
|
|
|
|
// Only warn for specific cases or when explicitly requested
|
|
if (process.env.NODE_ENV !== 'production' && options.warn !== false) {
|
|
// Don't warn for newly added components or fields that haven't been initialized yet
|
|
const isNewField = field && (field.includes('_') && /\d+$/.test(field));
|
|
if (!isNewField) {
|
|
console.warn(`Field '${field}' is missing or inaccessible.`);
|
|
}
|
|
}
|
|
return '';
|
|
}
|