File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -106,8 +106,25 @@ export function DjangoForm({
106106 const onSubmitEvent = ( event ) => {
107107 event . preventDefault ( ) ;
108108 const formData = new FormData ( form ) ;
109- console . log ( Object . fromEntries ( formData ) ) ;
110- onSubmitCallback ( Object . fromEntries ( formData ) ) ;
109+
110+ // Convert the FormData object to a plain object by iterating through it
111+ // If duplicate keys are present, convert the value into an array of values
112+ const entries = formData . entries ( ) ;
113+ const formDataArray = Array . from ( entries ) ;
114+ const formDataObject = formDataArray . reduce ( ( acc , [ key , value ] ) => {
115+ if ( acc [ key ] ) {
116+ if ( Array . isArray ( acc [ key ] ) ) {
117+ acc [ key ] . push ( value ) ;
118+ } else {
119+ acc [ key ] = [ acc [ key ] , value ] ;
120+ }
121+ } else {
122+ acc [ key ] = value ;
123+ }
124+ return acc ;
125+ } , { } ) ;
126+
127+ onSubmitCallback ( formDataObject ) ;
111128 } ;
112129
113130 // Bind the event listener
You can’t perform that action at this time.
0 commit comments