@@ -299,25 +299,14 @@ const DynamicForm = ({
299299
300300 if ( formData ?. dob ) {
301301 let age = calculateAgeFromDate ( formData ?. dob ) ;
302- let oldFormSchema = ( createNew && ! isCompleteProfile )
303- ? { ...schemaa , properties : { ...schemaa . properties } , required : [ ...( schemaa . required || [ ] ) ] }
304- : schemaa ;
305- let oldFormUiSchema = ( createNew && ! isCompleteProfile )
306- ? { ...uischema }
307- : uischema ;
308- let requiredArray = ( createNew && ! isCompleteProfile )
309- ? [ ...( oldFormSchema ?. required || [ ] ) ]
310- : oldFormSchema ?. required ;
302+ let oldFormSchema = schemaa ; // ✅ Use schemaa instead of formSchema
303+ let oldFormUiSchema = uischema ; // ✅ Use uischema instead of formUiSchema
304+ let requiredArray = oldFormSchema ?. required ;
311305
312306 //if learner form then only apply
313307 if ( oldFormSchema ?. properties ?. guardian_relation || isCompleteProfile ) {
314308 if ( age < 18 ) {
315- if ( createNew && ! isCompleteProfile ) {
316- // Avoid direct mutation of formData
317- } else {
318- delete formData ?. mobile ;
319- }
320-
309+ delete formData ?. mobile ;
321310 // Merge only missing items from required2 into required1 guardian details
322311 requiredKeys . forEach ( ( item ) => {
323312 if ( ! requiredArray . includes ( item ) ) {
@@ -343,7 +332,7 @@ const DynamicForm = ({
343332
344333 // Clone each key's config and set widget to 'CustomTextFieldWidget' with full width
345334 requiredKeys . forEach ( ( key ) => {
346- if ( Object . prototype . hasOwnProperty . call ( updatedUiSchema , key ) ) {
335+ if ( updatedUiSchema . hasOwnProperty ( key ) ) {
347336 updatedUiSchema [ key ] = {
348337 ...updatedUiSchema [ key ] ,
349338 'ui:widget' : 'CustomTextFieldWidget' ,
@@ -355,20 +344,11 @@ const DynamicForm = ({
355344 }
356345 } ) ;
357346
358- //hide mobile
347+ //hide mobile - remove from schema completely
359348 requiredKeys2 . forEach ( ( key ) => {
360- if ( createNew && ! isCompleteProfile ) {
361- // hide mobile - keep in schema to preserve value
362- updatedUiSchema [ key ] = {
363- ...updatedUiSchema [ key ] ,
364- 'ui:widget' : 'hidden'
365- } ;
366- } else {
367- // remove from schema completely (legacy behavior)
368- delete updatedUiSchema [ key ] ;
369- if ( oldFormSchema . properties && oldFormSchema . properties [ key ] ) {
370- delete oldFormSchema . properties [ key ] ;
371- }
349+ delete updatedUiSchema [ key ] ;
350+ if ( oldFormSchema . properties && oldFormSchema . properties [ key ] ) {
351+ delete oldFormSchema . properties [ key ] ;
372352 }
373353 } ) ;
374354
@@ -403,13 +383,9 @@ const DynamicForm = ({
403383
404384 oldFormUiSchema = reorderedUiSchema ;
405385 } else {
406- if ( createNew && ! isCompleteProfile ) {
407- // Avoid direct mutation of formData
408- } else {
409- delete formData ?. parent_phone ;
410- delete formData ?. guardian_relation ;
411- delete formData ?. guardian_name ;
412- }
386+ delete formData ?. parent_phone ;
387+ delete formData ?. guardian_relation ;
388+ delete formData ?. guardian_name ;
413389
414390 // remove from required
415391 requiredArray = requiredArray . filter (
@@ -427,7 +403,7 @@ const DynamicForm = ({
427403 const updatedUiSchema = { ...oldFormUiSchema } ;
428404 // Clone each key's config and set widget to 'hidden'
429405 requiredKeys . forEach ( ( key ) => {
430- if ( Object . prototype . hasOwnProperty . call ( updatedUiSchema , key ) ) {
406+ if ( updatedUiSchema . hasOwnProperty ( key ) ) {
431407 updatedUiSchema [ key ] = {
432408 ...updatedUiSchema [ key ] ,
433409 'ui:widget' : 'hidden' ,
@@ -474,13 +450,7 @@ const DynamicForm = ({
474450 // Remove guardian info note from schema and UI schema
475451 delete updatedUiSchema [ 'guardian_info_note' ] ;
476452 if ( oldFormSchema . properties && oldFormSchema . properties . guardian_info_note ) {
477- if ( createNew && ! isCompleteProfile ) {
478- const newProps = { ...oldFormSchema . properties } ;
479- delete newProps . guardian_info_note ;
480- oldFormSchema . properties = newProps ;
481- } else {
482- delete oldFormSchema . properties . guardian_info_note ;
483- }
453+ delete oldFormSchema . properties . guardian_info_note ;
484454 }
485455 oldFormUiSchema = updatedUiSchema ;
486456 }
@@ -491,66 +461,39 @@ const DynamicForm = ({
491461 }
492462 } else {
493463 //initially hide all
494- let oldFormSchema = ( createNew && ! isCompleteProfile )
495- ? { ...schemaa , properties : { ...schemaa . properties } , required : [ ...( schemaa . required || [ ] ) ] }
496- : formSchema ;
497- let oldFormUiSchema = ( createNew && ! isCompleteProfile )
498- ? { ...uischema }
499- : formUiSchema ;
464+ let oldFormSchema = formSchema ;
465+ let oldFormUiSchema = formUiSchema ;
500466 let requiredArray = oldFormSchema ?. required ;
501467
502468 // remove from required
503469 requiredArray = requiredArray . filter (
504470 ( key ) => ! requiredKeys . includes ( key )
505471 ) ;
506-
507- if ( createNew && ! isCompleteProfile ) {
508- // keep mobile in schema but hide in UI initially
509- } else {
510- requiredArray = requiredArray . filter (
511- ( key ) => ! requiredKeys2 . includes ( key )
512- ) ;
513- }
472+ requiredArray = requiredArray . filter (
473+ ( key ) => ! requiredKeys2 . includes ( key )
474+ ) ;
514475
515476 //set ui schema hide
516477 const updatedUiSchema = { ...oldFormUiSchema } ;
517478 // Clone each key's config and set widget to 'hidden'
518479 requiredKeys . forEach ( ( key ) => {
519- if ( Object . prototype . hasOwnProperty . call ( updatedUiSchema , key ) ) {
480+ if ( updatedUiSchema . hasOwnProperty ( key ) ) {
520481 updatedUiSchema [ key ] = {
521482 ...updatedUiSchema [ key ] ,
522483 'ui:widget' : 'hidden' ,
523484 } ;
524485 }
525486 } ) ;
526-
527487 requiredKeys2 . forEach ( ( key ) => {
528- if ( createNew && ! isCompleteProfile ) {
529- // hide mobile but keep in schema
530- if ( updatedUiSchema [ key ] ) {
531- updatedUiSchema [ key ] = {
532- ...updatedUiSchema [ key ] ,
533- 'ui:widget' : 'CustomTextFieldWidget' ,
534- } ;
535- }
536- } else {
537- delete updatedUiSchema [ key ] ;
538- if ( oldFormSchema . properties && oldFormSchema . properties [ key ] ) {
539- delete oldFormSchema . properties [ key ] ;
540- }
488+ delete updatedUiSchema [ key ] ;
489+ if ( oldFormSchema . properties && oldFormSchema . properties [ key ] ) {
490+ delete oldFormSchema . properties [ key ] ;
541491 }
542492 } ) ;
543-
544493 // Remove guardian info note from schema and UI schema initially
545494 delete updatedUiSchema [ 'guardian_info_note' ] ;
546495 if ( oldFormSchema . properties && oldFormSchema . properties . guardian_info_note ) {
547- if ( createNew && ! isCompleteProfile ) {
548- const newProps = { ...oldFormSchema . properties } ;
549- delete newProps . guardian_info_note ;
550- oldFormSchema . properties = newProps ;
551- } else {
552- delete oldFormSchema . properties . guardian_info_note ;
553- }
496+ delete oldFormSchema . properties . guardian_info_note ;
554497 }
555498 oldFormUiSchema = updatedUiSchema ;
556499 oldFormSchema . required = requiredArray ;
@@ -1540,24 +1483,18 @@ const customFields = {
15401483
15411484 if ( hasObjectChanged ( prevFormData . current , formData ) ) {
15421485 console . log ( 'hasObjectChanged in 1 formData' , formData ) ;
1543- const updatedFormData = ( createNew && ! isCompleteProfile ) ? { ...formData } : formData ;
1544-
15451486 if ( changedField ) {
15461487 //error set
15471488 console . log ( 'errors' , errors ) ;
15481489 setSubmitted ( false ) ;
15491490 //find out all dependent keys
15501491 const dependentKeyArray = getDependentKeys ( schema , changedField ) ;
1551- console . log ( 'hasObjectChanged in 2 formData' , updatedFormData ) ;
1492+ console . log ( 'hasObjectChanged in 2 formData' , formData ) ;
15521493 // console.log('hasObjectChanged dependent keys:', dependentKeyArray);
15531494 dependentKeyArray . forEach ( ( key ) => {
1554- if ( createNew && ! isCompleteProfile ) {
1555- delete updatedFormData [ key ] ; // Remove the key from cloned formData
1556- } else {
1557- delete formData [ key ] ; // Remove the key from formData
1558- }
1495+ delete formData [ key ] ; // Remove the key from formData
15591496 } ) ;
1560- // console.log('hasObjectChanged formData', updatedFormData );
1497+ // console.log('hasObjectChanged formData', formData );
15611498
15621499 setFormSchema ( ( prevSchema ) => {
15631500 const updatedProperties = { ...prevSchema . properties } ;
@@ -1586,14 +1523,14 @@ const customFields = {
15861523 return { ...prevSchema , properties : updatedProperties } ;
15871524 } ) ;
15881525
1589- // // console.log(`Field changed: ${changedField}, New Value: ${updatedFormData [changedField]}`);
1526+ // // console.log(`Field changed: ${changedField}, New Value: ${formData [changedField]}`);
15901527 // // console.log('dependentSchema', dependentSchema);
15911528 const workingSchema = dependentSchema ?. filter (
15921529 ( item ) => item . api && item . api . dependent === changedField
15931530 ) ;
15941531 // // console.log('workingSchema', workingSchema);
15951532 if ( workingSchema . length > 0 ) {
1596- const changedFieldValue = updatedFormData [ changedField ] ;
1533+ const changedFieldValue = formData [ changedField ] ;
15971534
15981535 const getNestedValue = ( obj , path ) => {
15991536 if ( path === '' ) {
@@ -1743,13 +1680,13 @@ const customFields = {
17431680 const isUsernameDisabled = formUiSchema ?. username ?. [ 'ui:disabled' ] === true ;
17441681 if ( isUsernameDisabled && prevFormData . current ?. username ) {
17451682 // Keep the existing username value when username field is disabled
1746- updatedFormData . username = prevFormData . current . username ;
1683+ formData . username = prevFormData . current . username ;
17471684 }
17481685
1749- prevFormData . current = updatedFormData ;
1750- // console.log('Form data changed:', updatedFormData );
1686+ prevFormData . current = formData ;
1687+ // console.log('Form data changed:', formData );
17511688 // live error
1752- setFormData ( updatedFormData ) ;
1689+ setFormData ( formData ) ;
17531690
17541691 function getSkipKeys ( skipHideObject , formData ) {
17551692 let skipKeys = [ ] ;
@@ -1763,7 +1700,7 @@ const customFields = {
17631700 return skipKeys ;
17641701 }
17651702
1766- const skipKeys = getSkipKeys ( hideAndSkipFields , updatedFormData ) ;
1703+ const skipKeys = getSkipKeys ( hideAndSkipFields , formData ) ;
17671704 // console.log('skipKeys', skipKeys);
17681705 let updatedUISchema = formUiSchemaOriginal ;
17691706 function hideFieldsInUISchema ( uiSchema , fieldsToHide ) {
@@ -1917,7 +1854,7 @@ const customFields = {
19171854
19181855 const transformedFormData = transformFormData (
19191856 cleanedData ,
1920- ( createNew && ! isCompleteProfile ) ? formSchema : schema ,
1857+ schema ,
19211858 extraFields
19221859 ) ;
19231860
@@ -2381,4 +2318,4 @@ const uiSchema = {
23812318 phoneDetails: { 'ui:widget': 'select' },
23822319 district: { 'ui:widget': 'select' },
23832320 };
2384- */
2321+ */
0 commit comments