fix: Improve robustness and error handling for dynamic form fields and sections with safe data access and type coercion.
This commit is contained in:
@@ -73,7 +73,9 @@ export default function EditProfilePage() {
|
||||
|
||||
// Then apply field default values where no existing data
|
||||
sortedSections.forEach(section => {
|
||||
section.fields?.forEach(field => {
|
||||
const sectionFields = Array.isArray(section.fields) ? section.fields : [];
|
||||
sectionFields.forEach(field => {
|
||||
if (!field || !field.slug) return; // Skip malformed fields
|
||||
if (field.defaultValue && initialData[field.slug] === undefined) {
|
||||
// Parse default value based on field type
|
||||
switch (field.fieldType) {
|
||||
@@ -186,12 +188,13 @@ export default function EditProfilePage() {
|
||||
const repErrors: Record<string, Record<string, Record<string, string>>> = {};
|
||||
|
||||
sections.forEach(section => {
|
||||
const sectionFields = Array.isArray(section.fields) ? section.fields : [];
|
||||
if (section.isRepeatable) {
|
||||
// Validate repeatable section entries
|
||||
const entries = repeatableData[section.slug] || [{}];
|
||||
entries.forEach((entry, entryIndex) => {
|
||||
section.fields?.forEach(field => {
|
||||
if (field.isRequired && field.isActive && !field.isSearchableOnly) {
|
||||
sectionFields.forEach(field => {
|
||||
if (field && field.isRequired && field.isActive && !field.isSearchableOnly) {
|
||||
const value = entry[field.slug];
|
||||
const isEmpty =
|
||||
value === undefined ||
|
||||
@@ -209,8 +212,8 @@ export default function EditProfilePage() {
|
||||
});
|
||||
} else {
|
||||
// Validate regular section fields
|
||||
section.fields?.forEach(field => {
|
||||
if (field.isRequired && field.isActive && !field.isSearchableOnly) {
|
||||
sectionFields.forEach(field => {
|
||||
if (field && field.isRequired && field.isActive && !field.isSearchableOnly) {
|
||||
const value = formData[field.slug];
|
||||
const isEmpty =
|
||||
value === undefined ||
|
||||
|
||||
Reference in New Issue
Block a user