- Updated the ComponentPreview component to utilize a new utility function, safeGetField, for safer field value retrieval from form data, enhancing data integrity and error handling. - Added a new "Read Only" toggle option in the FormBuilderFieldSettingsModal, allowing users to set fields as non-editable, improving form configuration flexibility. - Refactored various field access patterns to ensure consistent handling of undefined or null values across components. - Improved the overall user experience by ensuring that field states are accurately reflected and managed during form previews.
11 lines
447 B
JavaScript
11 lines
447 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)) {
|
|
return formData[field] !== undefined && formData[field] !== null ? formData[field] : '';
|
|
}
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
// Only warn in development
|
|
console.warn(`Field '${field}' is missing or inaccessible.`);
|
|
}
|
|
return '';
|
|
}
|