This repository was archived by the owner on Nov 22, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,34 @@ export class Form extends Screen {
54
54
...options ,
55
55
} )
56
56
57
+ // Polyfill the form attribute for IE11 and Edge
58
+ // (the click is sufficient here, because of the
59
+ // specification of implicit submissions in HTML5,
60
+ // see https://www.w3.org/TR/html5/single-page.html#implicit-submission)
61
+ // Note that this is not perfect -- in modern browsers,
62
+ // the type attribute is not required for submission;
63
+ // but it will help push users toward standard-conformant
64
+ // behavior so that the polyfill can be removed safely
65
+ // at some point in the future.
66
+ this . options . events [ 'click button[type="submit"]' ] = ( e ) => {
67
+ // If the button references another form...
68
+ if ( e . target . getAttribute ( 'form' ) ) {
69
+ // ... find it and ...
70
+ const targetForm = this . options . el . querySelector (
71
+ `form#${ e . target . getAttribute ( 'form' ) } `
72
+ )
73
+
74
+ // ... submit that form instead
75
+ // (this overrides the page structure, as per standard)
76
+ if ( targetForm ) {
77
+ return this . submit ( e )
78
+ }
79
+ }
80
+
81
+ // Otherwise stick to default behavior
82
+ return false
83
+ }
84
+
57
85
// Capture form submissions
58
86
this . options . events [ 'submit form' ] = e => this . submit ( e )
59
87
}
Original file line number Diff line number Diff line change @@ -253,6 +253,23 @@ describe('HTML-based components', () => {
253
253
} )
254
254
} )
255
255
256
+ it ( 'polyfills form attribute on submit buttons' , ( ) => {
257
+ // Test on the actual page, as above
258
+ f . options . el = null
259
+ f . options . content = '' +
260
+ '<form id="test">' +
261
+ '</form>' +
262
+ '<button type="submit" form="test">Click me</button>'
263
+
264
+ const spy = sinon . spy ( f , 'submit' )
265
+
266
+ return f . run ( ) . then ( ( ) => {
267
+ f . options . el . querySelector ( 'button' ) . click ( )
268
+ assert . ok ( spy . calledOnce )
269
+ f . options . el . innerHTML = ''
270
+ } )
271
+ } )
272
+
256
273
it ( 'ends after successful submission' , ( ) => {
257
274
f . options . content = exampleForm
258
275
You can’t perform that action at this time.
0 commit comments