@@ -268,13 +268,8 @@ function HTMLForm( {name, action, method, enctype, prefix, firstName, middleInit
268268 </cbp-slider>
269269 </cbp-form-field>
270270
271+
271272 <!-- File Inputs -->
272- <label>
273- Native File Input<br />
274- <input type="file" name="nativefileinput" multiple/>
275- </label><br /><br />
276-
277-
278273 <cbp-form-field label="Native File Input" description="Although styled as a design system input, this is a native file input in function.">
279274 <cbp-form-field-wrapper>
280275 <input type="file" name="nativefileinput" multiple>
@@ -322,10 +317,10 @@ const FormProcessingTemplate = ( args ) => {
322317
323318 // Set up event handlers for logging and setting errors on files via the `status` prop.
324319 setTimeout ( ( ) => {
325- const formEl = document . querySelector ( `form[name="${ name } "]` ) as HTMLFormElement ;
320+ const formEl = document . querySelector ( `form[name="${ args . name } "]` ) as HTMLFormElement ;
326321 const submitButton = document . querySelector ( 'button[type=submit]' ) as HTMLButtonElement ;
327322
328- // console.log('Event Listeners set: ', formEl, submitButton);
323+ console . log ( 'Event Listeners set: ' , formEl , submitButton ) ;
329324
330325 submitButton ?. addEventListener ( 'click' , e => {
331326 console . log ( 'Submit button pressed' , submitButton , e ) ;
@@ -349,13 +344,15 @@ const FormProcessingTemplate = ( args ) => {
349344 */
350345
351346 // List key/value pairs
347+ /*
352348 for(let [name, value] of formData) {
353349 console.log(`${name} =`, value);
354350 }
351+ */
355352 // Spreading the formData as an array seems to give the same results as above.
356- console . log ( 'formData (array spread): ' , [ ...formData ] ) ;
353+ console . log ( 'Native form submit - formData (array spread): ' , [ ...formData ] ) ;
357354 // This method makes the assumption that object keys are unique and only shows 1 value when they are not.
358- console . log ( 'formData as JS Object: ' , Object . fromEntries ( formData . entries ( ) ) ) ;
355+ // console.log('formData as JS Object: ', Object.fromEntries(formData.entries()));
359356
360357 /*
361358 formData.append("CustomField", "This is some extra data");
@@ -367,7 +364,7 @@ const FormProcessingTemplate = ( args ) => {
367364 */
368365
369366 } ) ;
370- } , 1000 ) ;
367+ } , 2000 ) ;
371368
372369 return `
373370 <h1>Native Form Tag</h1>
@@ -377,7 +374,9 @@ const FormProcessingTemplate = ( args ) => {
377374} ;
378375
379376export const FormProcessing = FormProcessingTemplate . bind ( { } ) ;
380-
377+ FormProcessing . args = {
378+ name : 'nativeForm'
379+ }
381380
382381
383382
@@ -386,7 +385,7 @@ const FormComponentProcessingTemplate = (args) => {
386385
387386 // Set up event handlers for logging and setting errors on files via the `status` prop.
388387 setTimeout ( ( ) => {
389- const formEl = document . querySelector ( `form[name="${ name } "]` ) as HTMLFormElement ;
388+ const formEl = document . querySelector ( `form[name="${ args . name } "]` ) as HTMLFormElement ;
390389 const submitButton = document . querySelector ( 'button[type=submit]' ) as HTMLButtonElement ;
391390
392391 //console.log('Event Listeners set: ', formEl, submitButton);
@@ -397,39 +396,8 @@ const FormComponentProcessingTemplate = (args) => {
397396
398397 formEl ?. addEventListener ( 'submit' , e => {
399398 console . log ( 'Native Form submit' , formEl , e ) ;
400- e . preventDefault ( ) ;
401-
402399 let formData = new FormData ( formEl ) ;
403- // Data can be added to the formData for submission:
404- //formData.append("CustomField", "This is some extra data");
405-
406- /*
407- * Because formData is an iterable, logging it does not show its name/value pairs.
408- * There are a number of ways to get at this, however, all of which require
409- * adding "dom.iterable", to compilerOptions > lib in tsconfig.json to avoid the
410- * following TypeScript/compile error:
411- *
412- * Type 'FormData' must have a '[Symbol.iterator]()' method that returns an iterator.
413- */
414-
415- // List key/value pairs
416- for ( let [ name , value ] of formData ) {
417- console . log ( `${ name } =` , value ) ;
418- }
419- // Spreading the formData as an array seems to give the same results as above.
420- console . log ( 'formData (array spread): ' , [ ...formData ] ) ;
421- // This method makes the assumption that object keys are unique and only shows 1 value when they are not.
422- //console.log('formData as JS Object: ', Object.fromEntries(formData.entries()));
423-
424- /*
425- formData.append("CustomField", "This is some extra data");
426- // formData can be manually submitted
427- const response = await fetch("stash.php", {
428- method: "POST",
429- body: formData,
430- });
431- */
432-
400+ console . log ( 'Native form submit - formData (array spread): ' , [ ...formData ] ) ;
433401 } ) ;
434402 } , 1000 ) ;
435403
@@ -445,4 +413,7 @@ const FormComponentProcessingTemplate = (args) => {
445413 ` ;
446414} ;
447415
448- export const FormComponentProcessing = FormComponentProcessingTemplate . bind ( { } ) ;
416+ export const FormComponentProcessing = FormComponentProcessingTemplate . bind ( { } ) ;
417+ FormComponentProcessing . args = {
418+ name : 'formComponent'
419+ }
0 commit comments